Recursive Grep with replace

I have seen some useful infomation about recursive grep in one of the thread. Can it is possible to combine resursive grep and replace togather? Means I need to replace old server names in all the files with new server names as we are upgrading our applications. There are lots of files in directories, subdirectories and server name is hardcoded lot of places. If possible, I want to find the server name recursively and then replace old_server_name with new_server_name. It would be like find-replace, find-replace but it would be with recursive grep. Thanks.

Try it on some test data first (maybe copy the files that need to be changed):

find /path/to/files -type f | xargs perl -i -pe 's/old_server_name/new_server_name/g'
1 Like
find . -type f -exec ex -sc '%s/old/new/g|x' {} \;

You may want to restrict the match to word boundaries with \< and \> . As with any mass editing, make sure to test thoroughly and/or have backups available.

Regards,
Alister

1 Like