Gnuru.org
Productive Linux


Subscribe

 Subscribe via Feedburner in a reader

Enter your email address:

Delivered by FeedBurner


Login
Login:
Password:



Don't have an account?
Sign up to Gnuru.org
Forgot your password?

Changing text in many files
24 June 2006 @ 09:33 BST
by Paul

Say you have a directory tree, of perl code, for example. You want to change some text in many files (Such as a package name, but it could be anything). You don't know which files the text is in, nor how many times the swap needs to be done.

Here's one way of doing it:

find lib -name '*pm' -exec perl -pi -e 's/foo/bar/g' {} \;

This finds all files that end in 'pm' in the directory tree starting with 'lib'. It changes all instances of 'foo' to 'bar' and writes over the original file.

There are probably other ways of doing this too.




Comments disabled