Pages

Wednesday, 8 August 2012

Script For find & replace string in a mutple file in unix.

Copy the below script to a file and rename the file as *.sh then give execution permission  to the corresponding file. then save this file to that location where you want to search for the string to be replaced. 

-------------
for fl in *.php; do
mv $fl $fl.old
sed ‘s/FINDSTRING/REPLACESTRING/g’ $fl.old > $fl
#rm -f $fl.old
done
--------------

then run

./*.sh [that file containing script]

Done !

Reference : http://gabeanderson.com/2008/02/01/unixlinux-find-replace-in-multiple-files/

No comments:

Post a Comment