Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uakari.primate.wisc.edu!ginosko!husc6!spdcc!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.unix.wizards Subject: Re: awk and shell question Message-ID: <694@lakart.UUCP> Date: 27 Sep 89 19:25:16 GMT References: <785@root44.co.uk> Organization: Lakart Corporation, Newton, MA Lines: 35 gwc@root.co.uk (Geoff Clare) sez: > clewis@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@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+