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 | |
by jepri (Parson) on May 23, 2001 at 20:09 UTC | |
|
Re: Shell trick to edit many files with perl
by tphyahoo (Vicar) on Aug 09, 2005 at 13:38 UTC |