passing command line arguments to awk
Jim Chappell
msitd22 at ms3.UUCP
Tue Sep 23 02:34:59 AEST 1986
In article <731 at scc.UUCP>, steiny at scc.UUCP (Don Steiny) writes:
> In article <753 at moscom.UUCP>, de at moscom.UUCP (Dave Esan) writes:
> > >
> > > I surrender -- is it possible to pass command line arguments to awk?
> > > If so - how.
>
> awk ' statement ; . . . ' file
>
> be sure and use single quotes! Lots of awk characters have
> special meaning to the shell. The following prints the uids in
> the password file from highest to lowest:
>
> awk -F: '{ print $3 }' | sort -n -r
I bet it sits there forever more because of missing input, viz:
> awk -F: '{ print $3 }' \
/etc/passwd \
> | sort -n -r
Why not use the capabilities of awk documented in my (but maybe not your)
users manual:
SYNOPSIS
awk [ -Fc } [ prog ] [ parameters ] [ files ]
^^^^^^^^^^^^^^
...
_parameters_ in the form of x=...y=...etc., may be passed to awk.
Here's the stub of a script I use to produce reports by month of year, and
need to know how many days are in the month:
awk '{ ...
printf "Report for %s\n\n",month
for (i=1; i<=dm; i++)
...
} ' month=$1 \
dm=`case $1 in
Jan|Mar|May|Jul|Aug|Oct|Dec) echo 31;;
Feb) echo 28;;
Apr|Jun|Sep|Nov) echo 31;;
esac` data
Jim
--
Jim Chappell ...!seismo!vrdxhq!ms3!jrc
ISN Corp.
1235A Jeff Davis Hwy, Suite 605A
Arlington, Va 22202
More information about the Comp.unix
mailing list