I needed to change all files on an entire server after changing database servers. So all files pointing to the old server needed to be changed. Somewhat in the order of 100+ web site config files containing the IP address of the old server needed to have the hostname of the new server replaced.

This is the command that helped me to do that in one go.

grep -R –files-with-matches ‘OLDSTRING’ . | sort | uniq | xargs perl -pi~ -e ’s/OLDSTRING/NEWSTRING/’

Many thanks to http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html for this post in helping me get this major task done.