Find and replace text in multiple files

Use the find command to list all files matching the criteria and pipe through xargs to perl to find and replace the text with a regular expression (regexp) match. This example will replace oldtext with newtext in all .html files:

  find . -name '*.html' | xargs perl -pi -e 's/oldtext/newtext/g'

As always, back up all files before doing this. In the regexp, remember to escape the necessary characters, e.g. slashes.

Taken from a post at http://www.linuxquestions.org/questions/showthread.php?t=203801.

Last modified: 12/05/07 16:07:41
Go to top

Related Pages

No related pages or links.

Login/out

Login

Forgot Password?
Go to top
Go to top