[NTLUG:Discuss] sed question

Ralph Green, Jr severian at mail.joimail.com
Thu Apr 15 00:09:26 CDT 2004


Burton,
  Your code worked well enough, just as it was.  My original hope was to
have the substitution take place where the first matching server line
was found.  Your version puts them at the bottom of the file, which
works fine and is plenty good for now.  Now, I just need to get the PHP
scripts to call the awk script.  I know the exec  command.  I just have
to get it to run on this system.  Isn't debugging PHP fun?
Thank you for your help,
Ralph 

On Wed, 2004-04-07 at 08:40, Burton M. Strauss III wrote:
> Have you considered Awk?
> 
> BEGIN {
>    if(ARGC != 3) {
>      print "usage: awk -f script.awk ntp1 ntp2 <oldconf >newconf"
>      exit(0);
>    }
>    ntp2=ARGV[2]
>    ARGV[2]=""
>    ntp1=ARGV[1]
>    ARGV[1]=""
> }
> 
> # Retain server 127.xxxx lines
> /^server *127/ { print $0; next }
> 
> # Drop all other server lines
> /^server/ { next }
> 
> # Echo anything else
> { print $0 }
> 
> END {
>   # Now create our new server lines
>   print "server " ntp1
>   print "server " ntp2
> }
> 
> (I haven't actually tried the code, but it or something like it should work)
> 
> -----Burton





More information about the Discuss mailing list