I haven't seen this posted anywhere so I thought I'd share. Here's how to hook up the find command to perl using xargs. You will need find and xargs installed.
find . -iname "*.tmpl" -print0 | xargs -0r -iXX perl -pe's!\"(logo.jpg +\")!\"/$1!;' -i.bak XX

A quick dissection of what is happening there:
* find recursively searches for "*.tmpl" starting in the current directory (the first '.') and then prints out each filename it finds, with a \0 after each one (null terminated)
*xargs receives the filename list and then invokes perl, once for each filename, replacing the XX with the name of the file
*perl then does an inplace edit on the file

Much easier than writing your own directory-recursion script, although less portable. In this case it was very useful, because the graphic designer I'm working with kept sending me html where the graphics were linked relative to the current page, rather than absolute from wwwroot.

Replies are listed 'Best First'.
Re: Shell trick to edit many files with perl
by merlyn (Sage) on May 23, 2001 at 18:49 UTC
    Or rather than invoke Perl twice:
    use File::Find; my @new_list; find sub { push @new_list, $File::Find::name if --- some criterion here ---; }, @ARGV; @ARGV = @new_list; $^I = ".bak"; while (<>) { s/old/new/g; print; }

    -- Randal L. Schwartz, Perl hacker

      That's so much better than mine! I never knew I could do inplace edits from within the program.

      Plus I think mine will flake out if the file name starts with a space

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.

Re: Shell trick to edit many files with perl
by tphyahoo (Vicar) on Aug 09, 2005 at 13:38 UTC