Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!vrdxhq!ms3!msitd22 From: msitd22@ms3.UUCP (Jim Chappell) Newsgroups: net.unix Subject: Re: passing command line arguments to awk Message-ID: <482@ms3.UUCP> Date: Mon, 22-Sep-86 12:34:59 EDT Article-I.D.: ms3.482 Posted: Mon Sep 22 12:34:59 1986 Date-Received: Mon, 22-Sep-86 21:35:08 EDT References: <731@scc.UUCP> Distribution: net Organization: ISN - HIOS, Arlington, Va Lines: 58 Summary: Arguments to awk 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 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