Techno Thoughts!  Subscribe

Find and Replace Across Multiple Files

by ichilton on Mar.15, 2009, under UNIX

Have you ever needed to change the same thing in a load of files and have had to sit there and go through each one in turn and make the same change?

This is a really useful and simple command:

perl -pi -w -e 's/from text/to text/g;' *

It simply goes through all files matching * and runs the regular expression, ’s/from text/to text/g’ - which means replace all instances of “from text” with “to text”.  nifty!

:, , ,

4 Comments for this entry

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...