Wednesday, July 21, 2010

Replace a String in Unix

Now that we know how to find a string in a list of files in the home directory, we may also want to replace the string with something else..

Eg: Replacing a password in all the files as and when it is getting changed.

The command to do this is:

find . -type f -name "*.c" -print | xargs perl -i -pe 's/MYOLDPASSWORD/MYNEWPASSWORD/g'

No comments:

Post a Comment