help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: non-convergent file edit?


From: rader
Subject: Re: non-convergent file edit?
Date: Tue, 16 Mar 2004 09:42:25 -0600

 > > Assume...
 > > 
 > >  echo "01Jan70" > f
 > > 
 > > then is there a way to do
 > > 
 > >  mv f f.OLD && \
 > >  cat f.OLD | perl -ne "s/\d\d\w\w\w\d\d/`date +%d%h%y`/; print" > f && \
 > >  rm f.OLD
 > > 
 > > with editfiles??
 > > 
 > > Just curious.  Using shellcommands is a reasonable solution. 

 > From: Chris Edillon
 >   you could do something like this:
 > 
 >     any::
 >         { /tmp/f
 >           ReplaceAll "[[:digit:]]{2}[[:alpha:]]{3}[[:digit:]]{2}" With
 > "$(day)$(month)$(year)"
 >         }
 > 
 > but cfagent will complain that it is non-convergent since the string
 > you'd put in place will always match the regex so it will get re-edited
 > every run.  if you know that all of the date strings in question are
 > of a certain year or have some other static characteristic you could
 > put in the regex, it might work.  

Yeah, I played around with that.  The replacement string is the
same length as the regex and matches the regex, so the substitution
non-convergent... like saying in perl terms...

 $a = "A 01Jan70 B 01Jan70 C"; 
 $b = "16Mar04";
 while ( $a =~ /\d\d\w\w\w\d\d/ ) {
   $a =~ s/\d\d\w\w\w\d\d/$b/;
   print "oops!\n";
 }

Seems to me (a cfengine novice) that ReplaceAll should behave like
s/regex/newstr/g (magically converge?) or maybe there should be 

 ReplaceOnce regex With newstr

steve 
- - - 
systems & network guy
high energy physics
university of wisconsin





reply via email to

[Prev in Thread] Current Thread [Next in Thread]