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

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!nwnexus!Celestial.COM!ray
  3. From: ray@Celestial.COM (Ray Jones)
  4. Subject: Re: Reading a line from a file in Bourne
  5. Organization: Celestial Software, Mercer Island, WA
  6. Distribution: usa
  7. Date: Tue, 15 Dec 1992 22:15:42 GMT
  8. Message-ID: <1992Dec15.221542.7995@Celestial.COM>
  9. References: <SHUTTON.92Dec11112920@fokker.union.indiana.edu>
  10. Lines: 59
  11.  
  12. In <SHUTTON.92Dec11112920@fokker.union.indiana.edu> shutton@fokker.union.indiana.edu (Scott K. Hutton) writes:
  13.  
  14. >This is something that has eluded me  for a good while, but now I have
  15. >to find out.  How can  you read lines (yes, entire lines) sequentially
  16. >in from a file and store them in a variable.  For example:
  17.  
  18. >  for ITEM in `cat $FILENAME`
  19. >    do echo a full line: $ITEM
  20. >  done
  21.  
  22. >If you're given a file that contains:
  23.  
  24. >  Line one
  25. >  Line two
  26.  
  27. >This script would output
  28.  
  29. >  a full line: Line
  30. >  a full line: one
  31. >  a full line: Line
  32. >  a full line: two
  33.  
  34. >Any easy answers?
  35. no
  36. Scott,
  37. Here is a code segment that does about what you want.  In this case there is
  38. a file (a tab seperated, variable length field database) with the first line
  39. Fname    Lname    Company    Source    phone
  40. Note the changes of standard in from keyboard to file and back again.
  41.  
  42.        exec 4<&0
  43.      rm -f p.tmp 
  44.     grep -i $1 ${DATA} >p.tmp 
  45.         if test $# -gt 1
  46.         then
  47.         grep -i $2 p.tmp>g.tmp;mv g.tmp p.tmp
  48.         fi
  49.     HEAD=`sed 1q ${DATA}`
  50.     IFS="    "
  51.     exec 3<p.tmp
  52.     exec 0<&3
  53.     read $HEAD 
  54.     LINE=`echo $phone`
  55.     while [ -n "$LINE" ]
  56.     do
  57.     echo "${CLEAR}
  58.    Name:  $Fname $Lname 
  59. Company:  $Company
  60. Comment:  $Source
  61.   Phone:  $phone"
  62.  echo "Is this correct? (d to delete) \c"
  63.     exec 0<&4
  64.  
  65. Hope this helps.
  66. -- 
  67. INTERNET:  ray@Celestial.COM   Ray A. Jones; Celestial Software
  68. UUCP:   ...!thebes!camco!ray   6641 East Mercer Way
  69.              uunet!camco!ray   Mercer Island, WA 98040; (206) 947-5591
  70. The probability of one or more spelling errors in this missive approaches
  71.