passing command line arguments to awk

Brian Onn onn at utcs.uucp
Sat May 31 10:41:45 AEST 1986


In article <198 at comp.lancs.ac.uk> craig at comp.lancs.ac.uk (Craig Wylie) writes:
>
>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.
>
>
>Craig.

The only way I know of to pass command line arguments into awk is by
defining them as variables in an assign statement on the awk command line, ie

awk -f awkfile arg1=$1 arg2=$2 inputfile

will assign $1 to arg1, and $2 to arg2, inside the body of the awk program. It
is not possible to assign variable values in this manner to variables that
are used inside an action associated with the BEGIN pattern.

I am not sure how to do it with sed.

-- 
-----
Brian A. Onn
University of Toronto Computing Services
Erindale College.
..!{ihnp4,decvax,harpo,utcsri,{allegra,linus}!utzoo}!utcs!onn

    "We trained hard, but it seemed that every time we were beginning to
     form up into teams, we would be reorganized.  I was to learn later in
     life we tend to meet any new situation by reorganizing, and a wonderful
     method it can be for creating the illusion of progress while producing
     confusion, inefficiency and demoralization"
						 - Petronius Arbiter, 66 AD.



More information about the Comp.unix mailing list