[PLUG] Help needed, he sed
Russell Senior
seniorr at aracnet.com
Sun Nov 10 07:53:30 UTC 2002
>>>>> "Sandy" == Sandy Herring <sandy at herring.org> writes:
Sandy> Unless you want to `cat' the results into one file, this
Sandy> approach is not going to work for you. e.g.,
Sandy> sed 's/foo/bar/gw newfile' *.baz
Sandy> will result in the results all being written to newfile. You
Sandy> could grunt your way through this in a shell script - or take
Sandy> the elegant Perl approach...
Or if you don't want to get any of that perl stuff on you, you can
just use your handy shell 'for' loop, as in:
for i in *.cpp ; do sed 's/foo/bar/g' $i > ${i%%.cpp}.fixed ; done
And then, after making sure it is doing what you want:
for i in *.fixed ; do mv $i ${i%%.fixed}.cpp ; done
Or a little better (touching only the intended files)
for i in `grep -l foo *.cpp` ; do sed ...
Note the backticks. Salt to taste.
--
Russell Senior ``I've seen every kind of critter God ever made,
seniorr at aracnet.com and I ain't never seen a meaner, lower, more
stinkin' yellow hypocrite than you!''
-- Burl Ives as Rufus Hennessy
More information about the PLUG
mailing list