[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Command line search and replace

On Tue, Jan 09, 2001 at 11:29:31AM -0800, kmself@ix.netcom.com wrote:
:on Tue, Jan 09, 2001 at 08:20:18AM -0500, Jonathan D. Proulx (jon@ai.mit.edu) wrote:

:> find . -name *.txt -exec cp {} {}.tmp \; -exec sed s/foo/boo/g {} \; 
:> or writing a small shell/perl/sed/awk/whatever script that take the
:> original file as input ad -exec'ing that.
:Still doesn't work -- sed doesn't change files in place, it reads from
:file and writes to stdout.

You've been on this list a little while if I recall, and I suspec
could reason out the solution to the problem, given that you know sed
reads from a file and writes to stdout.  So why not provide the
obvious answer, rather than just point out the bug?

find . -name '*.txt' -exec cp {} {}.tmp \; -exec sed s/foo/boo/g {}.tmp
>  {} \;

also note that you must quote the wildcard '*.txt' to prevent shell
expantion, but I feel the example stands bugs and all.  Using xargs or
for i in `find . -name '*.txt'` can result in stack overflows if there
are alot of file (I don't know howmany, but it happened to me before
somewhere aroud 1700 files, so I'm betting on 1024 as the breaking
point, though it may be more or less)


Reply to: