Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!caen!math.lsa.umich.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!fuchs From: fuchs@it.uka.de (Harald Fuchs) Newsgroups: comp.unix.shell Subject: Re: A question on [a,ga,na]wk. Keywords: awk, gawk, nawk, csh Message-ID: Date: 30 Nov 90 17:57:47 GMT References: Sender: news@ira.uka.de (USENET News System) Distribution: comp.unix.shell Organization: University of Karlsruhe, FRG Lines: 41 bt00@PL118d.? (Binod K. Taterway) writes: >Is it possible to make use of c-shell variables in [g,n]awk scripts. >What I need to do some thing like this: > #!/bin/csh > set AWK=/usr/local/bin/gawk > set date=`date +%m/%d/%y` > # Now the awk script that uses $date: > $AWK -F: '{if ($3 == $date) {print $0}}' > # End of shell script. >I checked with [g,n]awk. Only gawk can access environment variables, >but I do not want to do "setenv date= ..", just "set date= ..". Any >suggestions? Or, am I stuck with using setenv? Solution 1, works for gawk and maybe for nawk: Use the -v flag #!/bin/csh set AWK=/usr/local/bin/gawk set date=`date +%m/%d/%y` # Now the awk script that uses $date: $AWK -v date=$date -F: '{if ($3 == date) {print $0}}' # End of shell script. Solution 2, works for every awk: Take $date out of the single quotes #!/bin/csh set AWK=/usr/local/bin/gawk set date=`date +%m/%d/%y` # Now the awk script that uses $date: $AWK -F: '{if ($3 == '"$date"') {print $0}}' # End of shell script. The double quotes are not necessary, but they will be if $date contains shell-metacharacters (e.g. spaces). BTW: shouldn't your subject line say A question on {a,ga,na}wk\. # :-) -- Harald Fuchs ... *gulp*