home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / question / 9435 < prev    next >
Encoding:
Internet Message Format  |  1992-07-26  |  1.2 KB

  1. Path: sparky!uunet!darwin.sura.net!jvnc.net!rutgers!cmcl2!hsdndev!news.cs.umb.edu!mzraly
  2. From: mzraly@cs.umb.edu (Michael S. Zraly)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: Bourne shell read command
  5. Message-ID: <1992Jul26.055745.5445@cs.umb.edu>
  6. Date: 26 Jul 92 05:57:45 GMT
  7. References: <1992Jul24.213654.29656@cs.umb.edu>
  8. Sender: news@cs.umb.edu (USENET News System)
  9. Organization: UMass/Boston Dept. of Math & CS
  10. Lines: 37
  11. Nntp-Posting-Host: cs.umb.edu
  12.  
  13. I wrote:
  14. >
  15. >I am looking to read a file containing lines of the form
  16. >
  17. >    field1    field2    field3
  18. >
  19. >from a shell file, setting the variables mac to field2 and
  20. >dir to field3 if field1 matches the variable abbrev.
  21. >
  22. >The following code does NOT work, but illustrates my meaning:
  23. >
  24. >    # this does NOT work
  25. >    while (read x y z junk < $afile)
  26. >    do
  27. >        if test $x = $abbrev
  28. >        then
  29. >            mac=$y        # 'export mac' doesn't help
  30. >            dir=$z
  31. >        fi
  32. >    done
  33. >
  34. >Does anyone have any ideas?
  35.  
  36. Oh well, its simpler than I thought:
  37.  
  38.     # this DOES work
  39.     str=`grep "^$abbrev" $afile`
  40.     mac=`echo "$str" | awk '{ print $2 }'`
  41.     dir=`echo "$str" | awk '{ print $3 }'`
  42.  
  43. Nobody replied, but I thought someone else might want to know.
  44.  
  45. -- Mike
  46.  
  47. -- 
  48. Mike Zraly        If you wanna end war 'n' stuff, you gotta
  49. mzraly@cs.umb.edu    sing LOUD!    -- Arlo Guthrie
  50.