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 Makefile.am etc
2. create a script replace.sh
#!/bin/bash
while read line
do
perl -pi -e "s/user1/user2/g" $line
done
3. give executable permissions to the script
chmod +x replace.sh
4. run replace script as
./replace.sh < list.txt
Comments
Post a Comment