Forum: Cfengine Help
Subject: Re: search and replace help
Author: zzamboni
Link to topic: https://cfengine.com/forum/read.php?3,20275,20279#msg-20279

Neil,

(?! ...) is a _zero-width_ negative look-ahead assertion. Since it's 
zero-width, it ensures that the text inside the assertion is not present at 
that point, but it does not actually match that text. So even though your regex 
ensures that "7200" is not present at that point, the match stops _before_ the 
200, and thus the new text is inserted at that point.

I believe what you want is something like this:

                edit_line => search_replace(
                   "HISTSIZE=.*$",
                   "HISTSIZE=${histsize}");

You don't even need to use the value in the regex, because cfengine will do the 
replacement in memory and only update the file (and thus mark it as repaired) 
if the result is different from what was already there.

Shameless plug: you could also do this using my set_variable_values() bundle: 
https://github.com/zzamboni/cfengine-copbl/blob/master/cfengine_stdlib.cf#L171 
. Which as an added benefit, will add the line if it does not exist already in 
the file :)

_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to