having spent the morning trying to work out how to pipe file paths from find into a perl edit-in-place operation, I thought i might as well leave the answer here for other searchers: Use xargs, in short, to pass the results in a properly separated way to the perl command.
(man xargs, man find and perldoc perlrun for the details.)
This example replaces all instances of /images/ with /other_images/ in all *.html files in or beneath the current directory.
find . -iname "*.html" -print0 | xargs -0 -n 1 perl -pi.bak -e "s/\/im +ages\//\/other_images\//ig" #or revised following comments below (for which thanks): find . -iname "*.html" -print0 | xargs -0 perl -pi.bak -e "s/\/images\ +//\/other_images\//ig"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: piping into -pie (aka site-wide search and replace in a line)
by merlyn (Sage) on Oct 16, 2003 at 15:40 UTC | |
|
Re: piping into -pie (aka site-wide search and replace in a line) (faster)
by tye (Sage) on Oct 16, 2003 at 15:42 UTC |