Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by Skeeve (Parson)
on Oct 05, 2005 at 07:53 UTC ( [id://497511]=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

  1. No need for the / after the .
  2. You forgot to put a \ in front of *
    If you don't put it there your find will fail as soon as you have *.txt files in the current directory because the shell will replace "*.txt" by a list of those files.
So:
perl -pi -w -e 's/find/replace/g' `find . -name \*.txt`
OTOH: I prefer to use xargs for situations like this, just because the command line usually has limits.
find . -name \*.txt -print0 | xargs -0 perl -pi -w -e 's/find/replace/ +g'

$\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print

Replies are listed 'Best First'.
Re^3: One-line shell script for find and replace
by ruoso (Curate) on Oct 05, 2005 at 18:17 UTC

    I still prefer:

    find . -name '*.txt' -exec perl -pi -e 's/find/replace/g' {} \;
    daniel
      In the prior solution, you execute the perl interpreter once. In yours, you execute it many times. You gain maybe a little clarity, but you lose on performance. Only pointing this out if you have 10k files to deal w/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found