Mail Archives: djgpp/1997/11/11/09:47:55
On Tue, 11 Nov 1997, Peter Palotas wrote:
> Is there a GNU util, which replaces words/phrases in text-files? Kind of
> like grep but with a replacing option?
Use Sed (v2gnu/sed118b.zip). It's a batch editor. For example, the
following will replace "foo" with "fubar" in the file foo.txt and put it
into fubar.txt:
sed 's/foo/fubar/g' foo.txt > fubar.txt
If you want to rewrite foo.txt itself, use `cat' (from Textutils,
v2gnu/txt122b.zip), like this:
cat foo.txt | sed 's/foo/fubar/g' > fubar.txt
(When Sed is not given input files, it reads its stdin.)
The quotes in the Sed command are only required if the text you are
replacing includes whitespace.
- Raw text -