home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!purdue!mentor.cc.purdue.edu!sage.cc.purdue.edu!davisre
- From: davisre@sage.cc.purdue.edu (Robert Davis)
- Subject: Re: multiple sub's with 'sed'
- Message-ID: <C19uz1.43t@mentor.cc.purdue.edu>
- Sender: news@mentor.cc.purdue.edu (USENET News)
- Organization: Purdue University Computing Center
- References: <19891@mindlink.bc.ca>
- Date: Fri, 22 Jan 1993 20:16:11 GMT
- Lines: 28
-
- In article <19891@mindlink.bc.ca> Ian_Staines@mindlink.bc.ca (Ian Staines) writes:
- >
- >for WORD in ${LIST}
- >do
- > BOLD="${bold}${WORD}${unbold}"
- > sed "/s/${WORD}/${BOLD}/gw ${FILE}" ${FILE}
- >done
- >
- >The shell appears to keep ${FILE} intact within the script, and does not
- >updated it with each loop. I only get the last substitution, not the entire
- >list.
-
- sed's w command writes the pattern space to a file, creating
- the file if it does not exist, and *overwriting* it if it does. You
- want it to *append* the pattern space to $FILE, but sed does not have
- an option for that.
-
- You could use your "for" loop to construct a sed command and
- then execute the command after the loop. If you only have a few
- words, the sed command could be stored in a shell variable -- many
- words would require a temporary file.
-
-
- Rob
- --
- | Robert Davis davis@sonata.cc.purdue.edu
- | "Look up, Hannah. Look up." NeXT Mail accepted
- --
-