home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!mips!swrinde!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!casbah.acns.nwu.edu!navarra
- From: navarra@casbah.acns.nwu.edu (John Navarra)
- Newsgroups: comp.unix.questions
- Subject: Re: Passing shell variable in if statement in awk
- Message-ID: <1992Aug22.033720.7196@news.acns.nwu.edu>
- Date: 22 Aug 92 03:37:20 GMT
- References: <1992Aug21.114503.18212@news.acns.nwu.edu> <sherman.714444204@foster>
- Sender: usenet@news.acns.nwu.edu (Usenet on news.acns)
- Organization: Northwestern University, Evanston Illinois.
- Lines: 28
-
- In article <sherman.714444204@foster> sherman@unx.sas.com (Chris Sherman) writes:
- >No variable replacements happen inside single-quoted sections of code.
- >Above, where you do an awk ' blah blah ', nothing gets replaced inside.
- >
-
- After further review, the following worked for me:
-
- awk '
- /'"$pattern1"'/,/'"$pattern2"'/ {
- if ( "'"$shownumbers"'" )
- printf("[%d] \t %s \n", NR, $0)
- else
- printf("%s\n",$0)
- }' -
-
-
- For some reason I am not completely cognizant of yet, the
- shell stripped off the quotes in the if statement! Thus, awk was
- looking for the variable 'yes' (which it did not find and thus returned
- a 0). However, when I enclosed the statement in double quotes (again)
- all worked fine. The pattern1 and pattern2 variables work fine in the
- pattern matching construct.
-
- -tms
- --
- From the Lab of the MaD ScIenTiST:
-
- navarra@casbah.acns.nwu.edu
-