home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / shell / 5469 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.4 KB  |  40 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!purdue!mentor.cc.purdue.edu!sage.cc.purdue.edu!davisre
  3. From: davisre@sage.cc.purdue.edu (Robert Davis)
  4. Subject: Re: multiple sub's with 'sed'
  5. Message-ID: <C19uz1.43t@mentor.cc.purdue.edu>
  6. Sender: news@mentor.cc.purdue.edu (USENET News)
  7. Organization: Purdue University Computing Center
  8. References: <19891@mindlink.bc.ca>
  9. Date: Fri, 22 Jan 1993 20:16:11 GMT
  10. Lines: 28
  11.  
  12. In article <19891@mindlink.bc.ca> Ian_Staines@mindlink.bc.ca (Ian Staines) writes:
  13. >
  14. >for WORD in ${LIST}
  15. >do
  16. >        BOLD="${bold}${WORD}${unbold}"
  17. >        sed "/s/${WORD}/${BOLD}/gw ${FILE}" ${FILE}
  18. >done
  19. >
  20. >The shell appears to keep ${FILE} intact within the script, and does not
  21. >updated it with each loop.  I only get the last substitution, not the entire
  22. >list.
  23.  
  24.     sed's w command writes the pattern space to a file, creating
  25. the file if it does not exist, and *overwriting* it if it does.  You
  26. want it to *append* the pattern space to $FILE, but sed does not have
  27. an option for that.
  28.  
  29.     You could use your "for" loop to construct a sed command and
  30. then execute the command after the loop.  If you only have a few
  31. words, the sed command could be stored in a shell variable -- many
  32. words would require a temporary file.
  33.  
  34.  
  35. Rob
  36. -- 
  37. | Robert Davis                                    davis@sonata.cc.purdue.edu
  38. | "Look up, Hannah.  Look up."                            NeXT Mail accepted
  39. --
  40.