cat filename | sed s/string 1/string 2/g > filename2

Cat simply reads the contents of file called filename, and sends it into a
pipeline.

The | char (called pipe or vertical bar) joins two components of the pipe,
so that the output of one goes into the input of the next.

Sed is (s for) searching for string 1 and replacing it with string2.  The g
means keep searching in the line for more matches.  Please note, sed is
"stream editor" and works best on input based on lines.  If you need to get
tricky with line breaks and alternate spellings then you're on your own.
Another note, the / is convention, but you can use any character straight
after the s...  Eg   sed s@/@[EMAIL PROTECTED]    would replace every / with a .

Other useful utils are awk and tr.  See man for details on those.

The > redirects the output of the sed command to a file named filename2.
This is so you don't overwrite your input on any form of error.

That's the basic usage...  If you want any more help then we'll need to know
the details.


-----Original Message-----
From: Barry [mailto:[EMAIL PROTECTED] 
Sent: Thursday, 1 June 2006 5:10 p.m.
To: [email protected]
Subject: Replacing text


Hi

I want to parse a text file and replace a quoted expression with a 2nd 
expression.(actually a blank) I guess sed is the utility to use but what 
is the syntax please

TIA
Barry


Reply via email to