awk and shell question
David Goodenough
dg at lakart.UUCP
Thu Sep 28 05:25:16 AEST 1989
gwc at root.co.uk (Geoff Clare) sez:
> clewis at eci386.UUCP (Chris Lewis) writes:
>>This technique is in some of the AT&T UNIX V3 UNIX documentation. And
>>appears in many well written awk programs that have been published.
>>I use it *very* extensively (10K+ awk scripts in production code):
>>
>>a=`awk -F: '$1 == "'$LOGNAME'" { print $5}'`
> ^ /etc/passwd missing
> I find it much more readable, and less prone to error, to assign the
> necessary awk variables on the command line:
>
> a=`awk -F: '$1 == LOGNAME { print $5 }' LOGNAME="$LOGNAME" /etc/passwd`
>
> The only problem with this method is if you want awk to read stdin.
Try the following:
awk < file >> otherfile 'BEGIN {
np = '`head -1 $datadir/$job`'
ml = "'$mailer'"
jbu = "'`echo $job | tr a-z A-Z`'"
dd = "'$datadir'"
ta = "'$targ'"
}
rest of awk script follows ....
Lets you get away with murder :-) Note that by judicious use of `` I can
even get the output of a separate shell command into an awk variable:
for example np gets a number from the first line of $datadir/$job
--
dg at lakart.UUCP - David Goodenough +---+
IHS | +-+-+
....... !harvard!xait!lakart!dg +-+-+ |
AKA: dg%lakart.uucp at xait.xerox.com +---+
More information about the Comp.unix.wizards
mailing list