
using unix utility in awk expression
Quote:
> Hi,
> On 31 Oct 2002 10:36:45 -0800
> > The general question is if it is possible to run a (unix) utlity
within
> > such an awk expression to run against an output?
> > Thanks,
> > Mike
> you can use the system funkion :
> system(cmd-line)
> like this :
> ls -l | awk '{chek=sprintf("cksum %s", $9); printf ("%s\n", $9 ,
system(chek)) } '
> ok, it's not elegant like GROG's one, but it shows how to use unix
programms in awk.
> Iqbal
The problem with using system() is that its output and that of awk can
be mixed up on the screen. It is easier to use getline to read the
output of the cksum invocation via a pipe:
ls -l | awk '{("cksum "$9) | getline; print $3"\t"$1}'
gawk will even, on suitable systems, allow a two-way pipe between
processes using the |& operator.
[BTW On my systems cksum outputs the checksum, file size and file name,
so the need for ls and awk is even less there.]
HTH
--
Peter S Tillier peter{dot}tillier<at>btinternet[dot]com
To email me direct please use the above address
This post represents the views of the author and does not
necessarily accurately represent the views of BT