home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / question / 10286 < prev    next >
Encoding:
Internet Message Format  |  1992-08-21  |  1.4 KB

  1. 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
  2. From: navarra@casbah.acns.nwu.edu (John Navarra)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: Passing shell variable in if statement in awk
  5. Message-ID: <1992Aug22.033720.7196@news.acns.nwu.edu>
  6. Date: 22 Aug 92 03:37:20 GMT
  7. References: <1992Aug21.114503.18212@news.acns.nwu.edu> <sherman.714444204@foster>
  8. Sender: usenet@news.acns.nwu.edu (Usenet on news.acns)
  9. Organization: Northwestern University, Evanston Illinois.
  10. Lines: 28
  11.  
  12. In article <sherman.714444204@foster> sherman@unx.sas.com (Chris Sherman) writes:
  13. >No variable replacements happen inside single-quoted sections of code.
  14. >Above, where you do an awk ' blah blah ', nothing gets replaced inside.
  15. >
  16.     
  17.     After further review, the following worked for me:
  18.  
  19. awk '
  20. /'"$pattern1"'/,/'"$pattern2"'/ {
  21.     if ( "'"$shownumbers"'" )
  22.     printf("[%d] \t %s \n", NR, $0)
  23.     else
  24.     printf("%s\n",$0)
  25. }' -
  26.  
  27.  
  28.     For some reason I am not completely cognizant of yet, the 
  29. shell stripped off the quotes in the if statement! Thus, awk was 
  30. looking for the variable 'yes' (which it did not find and thus returned
  31. a 0). However, when I enclosed the statement in double quotes (again)
  32. all worked fine. The pattern1 and pattern2 variables work fine in the
  33. pattern matching construct. 
  34.  
  35. -tms 
  36. -- 
  37. From the Lab of the MaD ScIenTiST:
  38.                     
  39. navarra@casbah.acns.nwu.edu        
  40.