home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!nwnexus!Celestial.COM!ray
- From: ray@Celestial.COM (Ray Jones)
- Subject: Re: Reading a line from a file in Bourne
- Organization: Celestial Software, Mercer Island, WA
- Distribution: usa
- Date: Tue, 15 Dec 1992 22:15:42 GMT
- Message-ID: <1992Dec15.221542.7995@Celestial.COM>
- References: <SHUTTON.92Dec11112920@fokker.union.indiana.edu>
- Lines: 59
-
- In <SHUTTON.92Dec11112920@fokker.union.indiana.edu> shutton@fokker.union.indiana.edu (Scott K. Hutton) writes:
-
- >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
-
- >Any easy answers?
- no
- Scott,
- Here is a code segment that does about what you want. In this case there is
- a file (a tab seperated, variable length field database) with the first line
- Fname Lname Company Source phone
- Note the changes of standard in from keyboard to file and back again.
-
- exec 4<&0
- rm -f p.tmp
- grep -i $1 ${DATA} >p.tmp
- if test $# -gt 1
- then
- grep -i $2 p.tmp>g.tmp;mv g.tmp p.tmp
- fi
- HEAD=`sed 1q ${DATA}`
- IFS=" "
- exec 3<p.tmp
- exec 0<&3
- read $HEAD
- LINE=`echo $phone`
- while [ -n "$LINE" ]
- do
- echo "${CLEAR}
- Name: $Fname $Lname
- Company: $Company
- Comment: $Source
- Phone: $phone"
- echo "Is this correct? (d to delete) \c"
- exec 0<&4
-
- Hope this helps.
- --
- INTERNET: ray@Celestial.COM Ray A. Jones; Celestial Software
- UUCP: ...!thebes!camco!ray 6641 East Mercer Way
- uunet!camco!ray Mercer Island, WA 98040; (206) 947-5591
- The probability of one or more spelling errors in this missive approaches
-