On Mon, 4 Jun 2007, David B. wrote:
I am using 'find' to batch file a sed search and replace. Sed, of course,
outputs to stdout, the problem I am having is finding the correct syntax so
that I can change the extension of the input file to create the new output
file. For example:
Find . -name "*.htm" -exec 'sed s/old/new/' > '{}'.new
From what I've read, I should be able to use the '{}' as a global replace;
so if the input file happens to be smith.htm, then '{}' would be smith.htm
and the idea is that the output filename for the sed command would create a
new output file called smith.htm.new.
Here's a solution with sh+find+sed:
for file in $(find . -name "*.htm"); do sed 's/old/new/' $file > $file.new; done
--
Antti Harri