On Mon, Jun 04, 2007 at 12:30:49AM -0700, Bryan Irvine wrote:
> On 6/4/07, David B. <[EMAIL PROTECTED]> wrote:
> >hi, I'm using 3.8, and I hate to bother, but I have spent two days on the
> >net trying to find the answer to this problem.
> >
> >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.
> 
> I'd probably use a for loop.
> 
> *untested*
> for i in *.html ; do mv $i `echo $i | sed 's/\(.*\.\)html/\1html.new/'` ; 
> done

Don't use for loops with find results, they do not scale well.
Also, beware of spaces in file.

For this kind of thing, I generally use 'while read'

find . -type f -name \*.htm -print|while read f; do sed s/old/new <"$f" 
>"$f.new"; done

Reply via email to