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)
Or you could use
find . -type f -exec sed -i=~ -e 's/oldtext/newtext/g' and reduce the number of utilities involved by 1
Posted by Paul Dunbar | April 14, 2008 3:43 PM
Posted on April 14, 2008 15:43
thanks for the input, Paul.
Posted by Ramkumar Menon | April 14, 2008 4:19 PM
Posted on April 14, 2008 16:19
According to the title, you are using UNIX and sed -i is a Linux-only parameter.
So on Solaris and AIX, use perl :-)
Posted by Laurent Schneider | April 15, 2008 1:18 AM
Posted on April 15, 2008 01:18
Thanks for pointing out. I have modified the title to reflect this.
Posted by Ramkumar Menon | April 15, 2008 12:42 PM
Posted on April 15, 2008 12:42