« Reading only headers in an File/FTP Adapter and skipping the payload | Main | Dynamically updating bpel.xml properties within your BPEL Process »

Recursively replacing a string in all files in a directory [Linux]

My colleague provided me an extremely useful script that will replace a source string with a target string in all files in the current directory and its subdirectories.

find . -type f | xargs perl -pi~ -e 's/oldtext/newtext/g;'

Replace "oldtext" with the source string, and "newtext" with the target string.


During the replacement, all original files are backed up with a  "~" suffix.

Comments (4)

Paul Dunbar:

Or you could use

find . -type f -exec sed -i=~ -e 's/oldtext/newtext/g' and reduce the number of utilities involved by 1

Ramkumar Menon:

thanks for the input, Paul.

According to the title, you are using UNIX and sed -i is a Linux-only parameter.

So on Solaris and AIX, use perl :-)

Ramkumar Menon:

Thanks for pointing out. I have modified the title to reflect this.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on April 14, 2008 2:05 PM.

The previous post in this blog was Reading only headers in an File/FTP Adapter and skipping the payload.

The next post in this blog is Dynamically updating bpel.xml properties within your BPEL Process.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle