[SWLUG] Awk is driving me MAD!

Gareth James Powell gareth-j.powell at st.com
Wed Jun 11 10:11:19 UTC 2003


 Hi,
  
justin at discordia.org.uk wrote:
> 
> On Wed, 2003-06-11 at 09:08, Gareth James Powell wrote:
> > dick at acm.org wrote:
> > > or: awk '{printf("%s IN A %s\n", $2, $1);}' /etc/hosts
> 
> > ...as hosts on the works box I use has comment lines
> 
> You dont need to use a sed, awk can execute commands only for lines that
> match certain patterns, so to extend dicks version
> 
> awk '!/^#/{printf("%s IN A %s\n, $2, $1);} /etc/hosts
                                 ^          ^
  awk '!/^#/{printf("%s IN A %s\n", $2, $1);}' /etc/hosts

> 
> Which makes it run the code only for lines that do not start with a #

 That makes it a lot shorter! :-) ...but does not work on the Sun[1]
:-(  Thanks for trying anyway, it might be something very slightly
different for the Sun but I'm not an awk whizz or have the books. I
will give it a go on my Linux box later, which I suspect will like it
ok.

 Given that this is a Linux forum y'a might as well say so what if the
Sun won't run it? Who cares?...


Regards,
Gareth.


[1] awk '!/^#/{ printf("%s IN A %s\n", $2, $1); }'  /etc/hosts 
    /^#/{: Event not found




More information about the Swlug mailing list