Search And Replace in Multiple Files Using Perl

Hold on Cowboy

This blog post is pretty old. Be careful with the information you find in here. It's likely dead, dying, or wildly inaccurate.

perl -pi -w -e 's/search/replace/g;' *.php -e means execute the following line of code. -i means edit in-place -w write warnings -p loop

Example I had the following style sheet in a section:

and I wanted the following instead:

As each expression is a regular expression you’ve got to escape the special characters such as forward slash and . ..\/includes\/style.css

So the final line of code ends up as perl -pi -w -e ’s/..\/includes\/style.css/admin.css/g;’ *.php

Did this help you out? It took me a few days to piece together all this information together, I hope this saves you some time (who knows, maybe the future me will be thankful I wrote this down). Let me know your thoughts.