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/