[net.unix] csh, awk help

tiberio@seismo.UUCP (Mike Tiberio) (07/31/84)

I need help, i want to make the following bourne shell script run under
csh. This is not my actual script but has the same problems, how do
you pass parameters to an awk program? thanks... seismo!tiberio

#!/bin/sh
awk "BEGIN{id=$2;}{ \
	printf(\"%8d %s\n\", id++, \$0); \
	}" $1

mcferrin@inuxc.UUCP (P McFerrin) (08/03/84)

Parameters can be passed to awk of USG 5.0 systems by:

	awk [options] variable=value

The variable on the command line will have the specified value within the
program.  If I recall, the variable will NOT be set during the execution
on the BEGIN block.

rik@ucla-cs.UUCP (08/08/84)

Here's what I've found one has to use in csh scripts (I presume it will
work with sh as well):

#!/bin/csh
awk 'BEGIN{id='"$2"';}{ \
	printf(\"%8d %s\n\", id++, \$0); \
	}' $1

The quotes around $2 are necessary because $2 might contain blanks...

Rik Verstraete.					        rik@UCLA-CS.ARPA
					  ...!{ihnp4,ucbvax}!ucla-cs!rik