Forum: Cfengine Help Subject: Edit region of file - remove existing content Author: kholloway Link to topic: https://cfengine.com/forum/read.php?3,18633,18633#msg-18633
All, I'm trying to edit a file of any kind that has a start/end delimiter and I want to remove all the text between the start/end delimiter and replace it with the contents of another file. The insert portion works perfectly but the delete is being greedy and deleting EVERYTHING after the start delimiter. The code below is self contained for testing, it appears that the delete portion is not respecting the end delimiter. Delete_select portion is taken directly from the CF3 PDF manual and again does delete everything from start delim to EOF instead of to end delim. Thanks in advance for any suggestions! OS: Solaris 10 CF3 Ver: 3.0.5p1 bundle agent test { files: testhost:: "/tmp/test_dest.txt" comment => "Test, insert stuff into selected region of file", edit_line => insert_between_region('## CF3 DO NOT EDIT ##','/tmp/test_insert.txt'); } # Replace everything between start and end delimiters with our data # Start and end delim are the same for our test but could be different with some minor changes bundle edit_line insert_between_region(delim, insert_file) { delete_lines: ".*" select_region => start_end('${delim}','${delim}'), delete_select => example('${delim}'); insert_lines: "${insert_file}" select_region => start_end('${delim}','${delim}'), insert_type => 'file'; } body delete_select example(s) { delete_if_not_match_from_list => { @(s) }; #delete_if_not_contains_from_list => { $(s) }; } body select_region start_end(start,end) { select_start => "$(start)"; select_end => "$(end)"; include_start_delimiter => "false"; include_end_delimiter => "false"; } _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine