how to search/replace text in mutliple files?
Steven W. Orr
steveo at syslang.net
Wed Feb 11 19:33:39 UTC 2004
On Wednesday, Feb 11th 2004 at 15:10 -0400, quoth Trevor Smith:
=>On February 11, 2004 09:33 am, Piero Calucci wrote:
=>> btw if you are going to _replace_ text you should better look at sed or
=>> perl one-liners
Here's something I've been using for years:
replace_str
---------snippity------------------------Start here--------------------
#!/usr/local/bin/perl -i.old -w
use strict;
my $from_text = shift;
my $to_text = shift;
while( <> )
{
s/$from_text/$to_text/go;
print;
}
---------snippity------------------------End here--------------------
Just say something
replace_str oldstr newstr *.html
or if you have a lot of files
find blah | xargs replace_str oldstr newstr
Don't use the find -exec \; trick. It'll start a seperate child process
for each file it operates on.
--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
More information about the fedora-list
mailing list