Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!cmcl2!lanl!dph From: dph@lanl.ARPA (David P Huelsbeck) Newsgroups: net.unix Subject: Re: passing command line arguments to awk Message-ID: <7759@lanl.ARPA> Date: Mon, 22-Sep-86 05:48:21 EDT Article-I.D.: lanl.7759 Posted: Mon Sep 22 05:48:21 1986 Date-Received: Mon, 22-Sep-86 07:54:22 EDT References: <731@scc.UUCP> Reply-To: dph@a.UUCP (David P Huelsbeck) Distribution: net Organization: Los Alamos National Laboratory Lines: 37 In article <731@scc.UUCP> steiny@scc.UUCP (Don Steiny) writes: >In article <753@moscom.UUCP>, de@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 > > >-- >scc!steiny >Don Steiny @ Don Steiny Software >109 Torrey Pine Terrace >Santa Cruz, Calif. 95060 >(408) 425-0382 This is a special case but an important one. Using the -F option sets the field separator to the character . 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@lanl.arpa