A question on [a,ga,na]wk.

Arnold Robbins arnold at audiofax.com
Sat Dec 1 06:39:19 AEST 1990


In article <BT00.90Nov28155200 at PL118d.?> bt00 at PL118d.? (Binod K. Taterway) writes:
>Is it possible to make use of c-shell variables in [g,n]awk scripts.
>What I need to do some thing like this:
>
>  #!/bin/csh
>  set AWK=/usr/local/bin/gawk
>  set date=`date +%m/%d/%y`
>  # Now the awk script that uses $date:
>  $AWK -F: '{if ($3 == $date) {print $0}}' <source-file>
>  # End of shell script.

You can do variable assignments to awk variables on the command line.
The behaviour is most consistent with gawk and very recent versions of
nawk, but this should work with all awk variants:

	set date=`date +%m/%d/%y`
	$AWK -F: '{if ($3 == date) {print $0}}' date="$date" <source-file>

Of course, your awk program might better be written as

	$AWK -F: '$3 == date' date="$date" <source-file>

See the gawk manual for full details on the way the awk command line works.
-- 
Arnold Robbins				AudioFAX, Inc. | Laundry increases
2000 Powers Ferry Road, #200 / Marietta, GA. 30067     | exponentially in the
INTERNET: arnold at audiofax.com Phone:   +1 404 933 7612 | number of children.
UUCP:	  emory!audfax!arnold Fax-box: +1 404 618 4581 |   -- Miriam Robbins



More information about the Comp.unix.shell mailing list