delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/11/09:47:55

Date: Tue, 11 Nov 1997 16:46:55 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Peter Palotas <blizzar AT hem1 DOT passagen DOT se>
cc: djgpp AT delorie DOT com
Subject: Re: Replace program?
In-Reply-To: <3.0.16.19971111133622.ab9f3050@hem1.passagen.se>
Message-ID: <Pine.SUN.3.91.971111164258.17425D-100000@is>
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019