Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!agate!linus!linus!mbunix!mmk From: mmk@d62iwa.mitre.org (Morris M. Keesan) Newsgroups: comp.unix.shell Subject: Re: cat, pipes, and filters Message-ID: Date: 3 Jun 91 17:03:46 GMT References: <1991May31.165446.1530@progress.com> Sender: news@linus.mitre.org (News Service) Organization: The Mitre Corp., Bedford, MA. Lines: 19 In-Reply-To: root@progress.COM's message of Fri, 31 May 1991 16:54:46 GMT Nntp-Posting-Host: d62iwa.mitre.org In article <1991May31.165446.1530@progress.com> root@progress.COM (Root of all Evil) writes: [various ways to edit a file in place using sed as part of a pipeline, e.g.] > cat $FILE | sed s/"$ENTRY"/"$NEWENTRY"/ > $FILE It's interesting that most of the responses have pointed out the problem (creating the new $FILE before reading the old one), but all have accepted your initial premise, which is that "sed" is the appropriate tool for editing a file in place. It seems to me that the much more obvious approach is to use "ed", which is designed for editing files, as "sed" isn't. My approach, tested under Ultrix 4.1: #!/bin/sh #this replaces all occurrences of $ENTRY with $NEWENTRY ed $FILE <