in reply to Re: One-line shell script for find and replace
in thread One-line shell script for find and replace

There's a chance here of the combined list of files overrunning the shell command line buffer.
perl -MFile::Find -i -e 'find(sub{@ARGV=($_);s/find/replace/ while <>} +,".")'

Replies are listed 'Best First'.
Re^3: One-line shell script for find and replace
by Aristotle (Chancellor) on Oct 08, 2005 at 23:52 UTC

    Close, but you can do better.

    perl -MFile::Find -pi -e'BEGIN { find( sub { push @ARGV, $File::Find:: +name if /\.txt\z/i }, "." ) } s/find/replace/'

    With File::Find::Rule you write it more nicely.

    perl -MFile::Find::Rule -pi -e'BEGIN { @ARGV = File::Find::Rule->name( + "*.txt" )->in( "." ) } s/find/replace/'

    But in practice I’d use find -print0 | xargs -0 for this. Way too much work to do it in Perl.

    Makeshifts last the longest.