home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!spool.mu.edu!uwm.edu!linac!uchinews!machine!ddsw1!dattier
- From: dattier@ddsw1.mcs.com (DWT)
- Subject: Re: Reading a line from a file in Bourne
- Message-ID: <Bz8JLD.5Lp@ddsw1.mcs.com>
- Date: Mon, 14 Dec 1992 06:05:36 GMT
- Distribution: usa
- References: <SHUTTON.92Dec11112920@fokker.union.indiana.edu>
- Organization: Contributor Account at ddsw1, Chicago, Illinois 60657
- Lines: 41
-
- shutton@fokker.union.indiana.edu (Scott K. Hutton) wrote in
- <SHUTTON.92Dec11112920@fokker.union.indiana.edu>:
-
- | This is something that has eluded me for a good while, but now I have
- | to find out. How can you read lines (yes, entire lines) sequentially
- | in from a file and store them in a variable. For example:
- |
- | for ITEM in `cat $FILENAME`
- | do echo a full line: $ITEM
- | done
- |
- | If you're given a file that contains:
- |
- | Line one
- | Line two
- |
- | This script would output
- |
- | a full line: Line
- | a full line: one
- | a full line: Line
- | a full line: two
-
- By "this script" do you mean the one you want or the sample you listed?
- My guess is that you're talking about the sample you listed, because that's
- what it will do, and that you'd like this:
-
- a full line: Line one
- a full line: Line two
-
- | Any easy answers?
-
- while read fullline
- do echo a full line: "$fullline"
- done < $FILENAME
-
- That will give you some trouble with lines that end in backslashes, but
- it will complicate things to take care of those.
-
- David W. Tamkin Box 59297 Northtown Station, Illinois 60659-0297
- dattier@ddsw1.mcs.com CompuServe: 73720,1570 MCI Mail: 426-1818
-