Xref: utzoo comp.unix.questions:29343 comp.unix.shell:1660 Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!bionet!agate!ucbvax!dog.ee.lbl.gov!nosc!humu!pilikia!art From: art@pilikia.pegasus.com (Art Neilson) Newsgroups: comp.unix.questions,comp.unix.shell Subject: Re: Awk with passed parameters Keywords: awk bsd shell Message-ID: <1991Mar11.183426.5626@pilikia.pegasus.com> Date: 11 Mar 91 18:34:26 GMT References: <3022@dsacg3.dsac.dla.mil> <1991Mar08.141340.26881@convex.com> <1991Mar10.235414.28125@athena.mit.edu> Organization: Pilikia, Honolulu Lines: 30 In article <1991Mar10.235414.28125@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes: >In article <1991Mar08.141340.26881@convex.com>, tchrist@convex.COM (Tom Christiansen) writes: >|> The first thing is that you need to put your variable assignments >|> in front of your program. You probably should protect your string >|> literals with double quotes so it doesn't think they are variables. > > This is not true. Awk reads variable assignments in "file arguments" and >does the assignments *before* the main body of the awk program is executed. >The only problem with the program as originally posted was that he needed to >add "-" to the end of the awk command to tell it to read from stdin after >reading the other "file arguments" (which were actually variable assignments). > > If he adds that dash, then things should work on virtually any version of >awk, since variable assignments in file arguments were supported in very early >versions of awk and have continued to be supported in most versions. Tom, do >you know of a version of awk which won't work properly if an extra file >argument of "-" is added to the end of the awk command? Hey! use of that dash is a nifty trick. I have always done shell quoting tricks to pass shell parameters to old awk, the dash technique is a much better method. The following works fine on my system, although I need a + 0 on the day passed from the date command output in order to make it compare correctly with the day field in the ls command output (for days of the month between 1 and 9). This works for me: set `date` ls -l | awk '$6 == mm && $7 == dd + 0 { print }' mm=$2 dd=$3 - -- Arthur W. Neilson III | INET: art@pilikia.pegasus.com Bank of Hawaii Tech Support | UUCP: uunet!ucsd!nosc!pilikia!art