Re^2: awk and shell question

Greger Sernemar gs at diab.se
Wed Sep 27 03:29:56 AEST 1989


clewis at eci386.uucp (Chris Lewis) writes:

>In article <1163 at ispi.UUCP> jbayer at ispi.UUCP (Jonathan Bayer) writes:
>>
>>HELP!!  I have been pulling my hair out over this seemingly simple
>>problem:

>>a=" awk -F: '\$1 == \"$LOGNAME\" {
>>	user=\$5;
>>	print user
>>	}'"
>>USER=`cat /etc/passwd | $a`

>>I get the following error:

>Various ugly syntax errors.

Here is a solution to get parameters into an awk program:

a="`awk -F: '$1 == NAME {
       user=$5;
       print user
       }' NAME=$LOGNAME - `"

The last dash (-) closes standard input i.e enables other program to
pipe to the awk script. I was forced to either supply a file name or
a dash to be able to set the awk variable.
I'm not sure if this is a bug in the version of awk I'm using or not.
-- 
Greger Sernemar,  Diab Data AB
SNAIL: Box 2029, S-183 02 Taby, Sweden
ANALOG: +46 8-7680660
EMAIL: gs at diab.se , mcsun!sunic!diab!gs



More information about the Comp.unix.wizards mailing list