I wracked my brain over this one for some reason, and it turned out to
be so simple... I did find a few old threads asking for this, so I
though I'd share:


# Appends the supplied line if the regex supplied did not
# match an already existing line.
#
# files:
#   "myfile.txt"
#     edit_line => append_line_if_no_match(".*foo.*","foobar bas");
#
bundle edit_line append_line_if_no_match(regex,line)
{
classes:
  "regex_matched"
    expression =>regline("^$(regex)$","$(edit.filename)");

insert_lines:
  !regex_matched::
    "$(line)"
      comment => "Insert line if regex did not match";
}

-- 
Sjoerd Oostdijck                  RIPE Network Coordination Centre
RIPE NCC, IT Department                  Singel 258, Amsterdam, NL
http://www.ripe.net                                +31 20 535 4444

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to