D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Find & Replace across multiple files



On Saturday 30 November 2002  3:53 pm, you wrote:
Jonathan Melhuish wrote:
Anybody got any ideas on how to replace a long text string across
multiple text files, using only a piece of paper, a pen, a piece of
string and a linux box?

If all your files are in one directory, simple:

Using bash:
for file in REGEX; do sed -e 's/FIND_REGEX/REPLACE/g' $file > $file.new;
mv $file.new $file; done
(that's just one line, please excuse any line wrapping)
Replacing REGEX, FIND_REGEX, REPLACE with appropriate values.

So I say:

for file in *; do sed -e 's/[control-set]*[/control-set]/[comment]controls 
removed from here[/comment]/g' $file > $file.new; mv $file.new $file; done

And it says:

sed: -e expression #1, char 69: Unknown option to 's' 

I'm sure it's just a little typo, but I'm not quite sure how it all works. 
Yeah, I'll get around to reading the man pages sometime... ;-)

Cheers for your help!

Jon


--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.


Lynx friendly