Path: utzoo!utgpu!water!watmath!clyde!bellcore!rutgers!mailrus!purdue!decwrl!labrea!hanauma!karish
From: karish@hanauma.stanford.edu (Chuck Karish)
Newsgroups: comp.unix.questions
Subject: Re: accessing shell variables from within awk?
Summary: Use single quotes
Message-ID: <23473@labrea.Stanford.EDU>
Date: 20 Sep 88 04:45:02 GMT
References: <473@diamond.unix.ETA.COM>
Sender: news@labrea.Stanford.EDU
Reply-To: karish@hanauma.UUCP (Chuck Karish)
Distribution: na
Organization: Stanford University, Dept. of Geophysics
Lines: 17

In article <473@diamond.unix.ETA.COM> rscott@eta.unix.ETA.COM (Rich Scott)
writes:
>	How can I access a shell variable (to wit, a few environment
>variables) from within "awk"?

The awk command is usually written inside single quotes.  Use more
quotes to expose the shell variables you need.  The following program will
print a user's name and user ID number:

USRNAME="fred"
export USRNAME

awk -F':' '$1 ~ /'$USRNAME'/{print $1, $3}' /etc/passwd

Chuck Karish    ARPA:   karish@denali.stanford.edu
                UUCP:   {decvax,hplabs!hpda}!mindcrf!karish
                USPS:   1825 California St. #5   Mountain View, CA 94041