Saturday, June 27, 2015

How to replace substring in linux

There is an easy way to do a mass replace of substring in linux. You can use perl command and a combination of "find/xargs/perl" like this:

find -name '*.log' -type f -print0 | xargs --null perl -pi -e 's/redhat/SUSE/'

The you can tweak the first part of the command (find) to point it to the files which have to be changed. redhat will be replaced with SUSE for all log files in this case.

No comments:

Post a Comment