home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / shell / 5051 < prev    next >
Encoding:
Text File  |  1992-12-14  |  1.6 KB  |  53 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!spool.mu.edu!uwm.edu!linac!uchinews!machine!ddsw1!dattier
  3. From: dattier@ddsw1.mcs.com (DWT)
  4. Subject: Re: Reading a line from a file in Bourne
  5. Message-ID: <Bz8JLD.5Lp@ddsw1.mcs.com>
  6. Date: Mon, 14 Dec 1992 06:05:36 GMT
  7. Distribution: usa
  8. References: <SHUTTON.92Dec11112920@fokker.union.indiana.edu>
  9. Organization: Contributor Account at ddsw1, Chicago, Illinois  60657
  10. Lines: 41
  11.  
  12. shutton@fokker.union.indiana.edu (Scott K. Hutton) wrote in
  13. <SHUTTON.92Dec11112920@fokker.union.indiana.edu>:
  14.  
  15. | This is something that has eluded me  for a good while, but now I have
  16. | to find out.  How can  you read lines (yes, entire lines) sequentially
  17. | in from a file and store them in a variable.  For example:
  18. |   for ITEM in `cat $FILENAME`
  19. |     do echo a full line: $ITEM
  20. |   done
  21. | If you're given a file that contains:
  22. |   Line one
  23. |   Line two
  24. | This script would output
  25. |   a full line: Line
  26. |   a full line: one
  27. |   a full line: Line
  28. |   a full line: two
  29.  
  30. By "this script" do you mean the one you want or the sample you listed?
  31. My guess is that you're talking about the sample you listed, because that's
  32. what it will do, and that you'd like this:
  33.  
  34. a full line: Line one
  35. a full line: Line two
  36.  
  37. | Any easy answers?
  38.  
  39. while read fullline
  40.   do echo a full line: "$fullline"
  41. done < $FILENAME
  42.  
  43. That will give you some trouble with lines that end in backslashes, but
  44. it will complicate things to take care of those.
  45.  
  46. David W. Tamkin   Box 59297   Northtown Station, Illinois  60659-0297
  47. dattier@ddsw1.mcs.com    CompuServe: 73720,1570    MCI Mail: 426-1818
  48.