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

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!noc.msc.net!news.stolaf.edu!guenther
  3. From: guenther@stolaf.edu (Philip A Guenther)
  4. Subject: Re: Reading a line from a file in Bourne
  5. In-Reply-To: shutton@fokker.union.indiana.edu's message of Fri, 11 Dec 1992 16:29:20 GMT
  6. Message-ID: <GUENTHER.92Dec11140649@quelle.stolaf.edu>
  7. Sender: news@news.stolaf.edu
  8. Organization: Academic Computing Center, St. Olaf College
  9. References: <SHUTTON.92Dec11112920@fokker.union.indiana.edu>
  10. Distribution: usa
  11. Date: 11 Dec 92 14:06:49
  12. Lines: 35
  13.  
  14. In article <SHUTTON.92Dec11112920@fokker.union.indiana.edu> shutton@fokker.union.indiana.edu (Scott K. Hutton) writes:
  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.  
  19.      for ITEM in `cat $FILENAME`
  20.        do echo a full line: $ITEM
  21.      done
  22.  
  23.    If you're given a file that contains:
  24.  
  25.      Line one
  26.      Line two
  27.  
  28.    This script would output
  29.  
  30.      a full line: Line
  31.      a full line: one
  32.      a full line: Line
  33.      a full line: two
  34.  
  35.    Any easy answers?
  36.  
  37. How about:
  38.  
  39. while read i; do
  40.     echo A line: $i
  41. done <$FILENAME
  42.  
  43. Philip Guenther
  44. --
  45. guenther@stolaf.edu (Philip Guenther)       | The ACC might agree with me,
  46. Student Sys Prog, Academic Computing Center | but with that bunch, (and me)
  47. St Olaf College, Northfield, MN 55057-1001  | you never know... :-) :-| :-(
  48. "Life makes sense?  LIFE MAKES SENSE!!?  Where do people get these ideas?"-me
  49.