Thursday, October 24, 2013

Replace String in multiple files using Perl

1. Create a list of files that you want to replace the word in

e.g find . | grep Makefile | grep -v Makefile. > list.txt

This will list all Makefile's and exclude etc

2. create a script


while read line


perl -pi -e "s/user1/user2/g" $line


3. give executable permissions to the script

chmod +x

4. run replace script as

./ < list.txt

No comments:

Post a Comment