Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: One-line shell script for find and replace

by Anonymous Monk
on Oct 05, 2005 at 23:00 UTC ( [id://497775]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://497775]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-24 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found