Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

piping into -pie (aka site-wide search and replace in a line)

by thpfft (Chaplain)
on Oct 16, 2003 at 11:59 UTC ( [id://299716]=CUFP: print w/replies, xml ) Need Help??

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

    You'll fork and exec("perl",...) a lot fewer times if you drop the "-n 1" from xargs. This could be significantly faster in some cases.

                    - tye

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-24 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found