Jump to content

Perl find and replace


RopeADope

Recommended Posts

Hi all.

 

I have this line of code that I found to do a search and replace.  It works perfectly on a single file but I need to do multiple files in multiple directories.  How do I go about doing that?  Is there a flag I can add to the line of code?  (I don't know anything about perl)

 

 

perl -pi -w -e 's/search_string/replace_string/g;' *.php

 

Link to comment
https://forums.phpfreaks.com/topic/229415-perl-find-and-replace/
Share on other sites

Assuming this is being executed on Linux....

 

You don't even need Perl.

 

find -type f -name '*.php' -exec sed -i 's/search_string/replace_string/g' {} \;

 

of course you could still use it....

 

find -type f -name '*.php' -exec perl -pi -w -e 's/search_string/replace_string/g;' {} \;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.