passing command line arguments to awk

Pedz Thing pedz at bobkat.UUCP
Thu Sep 25 01:00:27 AEST 1986


In article <7759 at lanl.ARPA> dph at a.UUCP (David P Huelsbeck) writes:
>This is a special case but an important one. Using the -F<c> option sets the
>field separator to the character <c>. This is important because setting the
>field separator with:
>
>	awk '{ print $3 }' FS=\":\" | sort -n -r
>
>will not set the FS variable to ":". (at least on 4.2) I haven't checked but
>I suspect that it's caused by the fact that parameter values passed from the 
>command line are not made available until after the first record has been read
>and parsed. Other variables not used in parsing (such as OFS etc.) may be set
>in the way I've shown. In the case of RS I know of no way to set it from the
>command line.
>
>	dph at lanl.arpa


Try: awk 'BEGIN { FS=":" } { print $3 }' | sort -n -r

It works Wonders.  (Not to mention that the FS="... is a pattern in
this case and not a statement.)

The is the end of the article I intended on posting but inews has the
stupic feature that no article can have few original lines than quoted
lines.  In fact Pnews seems to have an additional feature of continual
harassment whenever you try to post an article with it.  I hate stupid
things like this.  They only provoke other stupid acts like this one
of posting more garbage to the net than before.  This is almost as
dumb as the attempt to force net.announce to be shipped to all sites
by rn refusing to work without it.  Even if net.announce is shipped
between sites (all sites) that is no guarantee that it will be read.
-- 
Perry Smith
ctvax ---\
megamax --- bobkat!pedz
pollux---/



More information about the Comp.unix mailing list