Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!udel!burdvax!wrp From: wrp@PRC.Unisys.COM (William R. Pringle) Newsgroups: comp.unix.misc Subject: Re: passing arguments to awk scripts Message-ID: <16788@burdvax.PRC.Unisys.COM> Date: 11 Mar 91 03:25:26 GMT References: <1991Mar9.212943.1961@casbah.acns.nwu.edu> <10094@uwm.edu> Distribution: na Organization: Unisys Corporation, Paoli Research Center; Paoli, PA Lines: 24 In article <10094@uwm.edu> datta@vacs.uwp.wisc.edu (David Datta) writes: >Can it be done? Is there a way I can address a >command line argument within the script? Awk (nawk, gawk, etc.) accept arguments as keyword-value pairs when entered from the command line. For example, to pass the current directory to awk, type something like: PWD=`pwd`, for your home directory, HOME=${HOME}, etc. For example, the following file (asdf): #!/bin/sh awk '{printf "Line %d of %s/%s: >>%s<<\n", NR, Pwd, FILENAME, $0}' \ Pwd=`pwd` asdf produces the following output: Line 1 of /guests/wrp/asdf: >>#!/bin/sh<< Line 2 of /guests/wrp/asdf: >><< Line 3 of /guests/wrp/asdf: >>awk '{printf "Line %d of %s/%s: >>%s<<\n", NR, Pwd, FILENAME, $0}' \<< Line 4 of /guests/wrp/asdf: >> Pwd=`pwd` asdf<< Bill Pringle wrp@prc.unisys.com