Last active
August 29, 2015 14:01
-
-
Save mhewedy/dab0116aa288f67d05ba to your computer and use it in GitHub Desktop.
bash file to refactor (find and replace)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
if [ $# -lt 2 ] | |
then | |
echo "usage $0 <old> <new>" | |
exit -1 | |
fi | |
old=$1 | |
new=$2 | |
#find in files | |
files=`grep -HR $old * |grep -v 'Binary file'| cut -d':' -f 1|sort|uniq` | |
for f in $files | |
do | |
file $f >/dev/null | |
if [ $? == 0 ] | |
then | |
echo "processing $f" | |
sed -i s/$old/$new/g $f | |
fi | |
done | |
# find files with same name and rename files | |
for f in `find ./ -name $old` | |
do | |
newfile=`dirname $f`/$new | |
echo "Renaming $f to $newfile" | |
mv $f $newfile | |
done | |
echo "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment