RopeADope Posted March 2, 2011 Share Posted March 2, 2011 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 More sharing options...
trq Posted March 3, 2011 Share Posted March 3, 2011 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;' {} \; Link to comment https://forums.phpfreaks.com/topic/229415-perl-find-and-replace/#findComment-1182159 Share on other sites More sharing options...
RopeADope Posted March 4, 2011 Author Share Posted March 4, 2011 Worked perfectly. Is there a cheat sheet for common tasks like this? Link to comment https://forums.phpfreaks.com/topic/229415-perl-find-and-replace/#findComment-1182796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.