passing command line arguments to awk

Mike Leibensperger leiby at masscomp.UUCP
Tue Sep 23 07:29:56 AEST 1986


In article <753 at moscom.UUCP> de at moscom.UUCP (Dave Esan) quotes someone else:
>> 
>> I surrender  --  is it possible to pass command line arguments to awk?
>> 
>> If so - how.  While I'm at it how about doing the same thing to sed.

One way to do it is to put your awk command in a shell script, and play
with shell quoting to put the shell arguments where you want them.
This example,

	:
	awk '{ s += $'$1' }
	END { print s }'


from _The_UNIX_Programming_Environment_ by Kernighan and Pike, shows the
basic idea.
--
Rt. Rev. Mike Leibensperger, Archbishop of Chelmsford
Church of St. Clint the Righteous  ("Feel lucky, Pink Boy?")
Masscomp; 1 Technology Park; Westford, MA 01886
{decvax,ihnp4,tektronix}!masscomp!leiby



More information about the Comp.unix mailing list