Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!rutgers!mcnc!rti!dg-rtp!hunt From: hunt@dg-rtp.rtp.dg.com (Greg Hunt) Newsgroups: comp.unix.questions Subject: Re: Narly Nawk Script Message-ID: <1990Dec11.185443.17413@dg-rtp.dg.com> Date: 11 Dec 90 18:54:43 GMT References: <4255@exodus.Eng.Sun.COM> Sender: usenet@dg-rtp.dg.com (Usenet Administration) Reply-To: hunt@dg-rtp.rtp.dg.com Organization: Data General Corp., Research Triangle Park, NC Lines: 68 In article <4255@exodus.Eng.Sun.COM>, bm@bike2work.Eng.Sun.COM (Bill Michel) writes: > > I'm working on a shell script that makes extensive use of (n)awk. > I'm *really confused as to the general workings of the script, and > would apprecieate some help. > Assume my script to be called "nawkfile" it is invoked as follows: > > nawkfile inputfile > > where inputfile is the file containing the input to be processed. > My main questions are : > > 1) where does the data put into "string" go after the first call > to nawk? > 2) does $* mean a recursive call to the script, if so, how can > this be used as input to the second nawk call > > The general layout is as follows > > nawk ' > { > process a bunch of text, and append it to the variable "string" > } > END { > print string > } > ' $* | > nawk ' > { > do some more processing > }' | > [ rest of script deleted ] 1. The data put into "string" is being written (by the print command) to the file descriptor called stdout (standard output). Using the pipe symbol "|", you have told the shell to connect the stdout from the first nawk to the stdin (standard input) of the second nawk. So, the data is being written through the pipe to the second nawk, which will use the data as input. Using a pipe to do this is called "redirecting" the input and output. 2. The "$*" doesn't indicate a recursive call. It is the way you get access to the command line arguments specified to the script. Specifically, $* means "get me all of the command line arguments", which in this case is only the name of the "inputfile". The shell substitutes the arguments in place of the $*, so the first nawk ends up being called with "inputfile" as its argument. You can reference $* as many times as you care to in the script. You can also get specific arguments by using $1, $2, etc. You don't need to use the $* for the second nawk to get it's input, you've already done that by using the pipe "|" from the first nawk. For more details on both of these points, you might want to look at the man page for the shell (use "man sh | more"). It will tell you about the various ways you can redirect input and output, and also the ways you can manipulate shell script arguments. Enjoy! -- Greg Hunt Internet: hunt@dg-rtp.rtp.dg.com DG/UX Kernel Development UUCP: {world}!mcnc!rti!dg-rtp!hunt Data General Corporation Research Triangle Park, NC, USA These opinions are mine, not DG's.