Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!princeton!caip!seismo!umcp-cs!cvl!umd5!zben From: zben@umd5.UUCP (Ben Cranston) Newsgroups: net.unix Subject: Re: passing command line arguments to awk Message-ID: <994@umd5.UUCP> Date: Thu, 29-May-86 18:39:13 EDT Article-I.D.: umd5.994 Posted: Thu May 29 18:39:13 1986 Date-Received: Sat, 31-May-86 06:38:46 EDT References: <198@comp.lancs.ac.uk> Reply-To: zben@umd5.UUCP (Ben Cranston) Distribution: net Organization: U of Md, CSC, College Park, Md Lines: 48 Summary: Can be done using $ subst within double quotes In article <198@comp.lancs.ac.uk> craig@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. I'm not sure if this is really what you are asking. You can use $n type substitution if you use double-quotes to delimit the program; however; beware that now all double-quotes and dollar signs in the program must be escaped with a backslash. Consider the following shell script, which looks a site up in the ARPA Internet site table: #! /bin/sh # host: Search InterNet host table for pattern case $1 in -a|-A) source=/u/netmap/hosts.txt; shift;; *) source=/u/netmap/lochosts.txt;; esac case $# in 0) echo 'Usage: host [-a] pattern' 1>&2; exit 2;; esac grep -i -e $1 <$source | sed 's/ //g' | awk -F: " BEGIN { nf=0 } \$1==\"HOST\" { if (\$4==\"\") \$4 = \"(Unknown)\" if (\$5==\"\") \$5 = \"(unknown)\" printf \"\n\" printf \"%s running %s with InterNet address %s\n\", \$4, \$5, \$2 printf \"Names: %s\n\", \$3 printf \"Services: %s\n\", \$6 nf += 1 } END { if (nf==0) print | \"echo $1 not found in $source 1>&2\" } " | more -20 The substitution I am talking about is in the "if (nf==0)" clause at the end - so it can say "luser.podunk.EDU not found" if it doesn't find it. Is that what you wanted? -- "We're taught to cherish what we have | Ben Cranston by what we have no longer..." | zben@umd2.umd.edu ...{seismo!umcp-cs,ihnp4!rlgvax}!cvl!umd5!zben