Created
July 28, 2014 07:53
-
-
Save shortdudey123/431b3787f5b7a3a10b94 to your computer and use it in GitHub Desktop.
Change filename and update words in file
This file contains hidden or 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 | |
echo "What directory would you like to execute this script on?" | |
echo "NOTE: do not execute this on the same directory that contains this script" | |
read FILEPATH | |
for file in $(echo $FILEPATH*); do | |
filenew=`echo $file | sed 's/foo/bar/g'` | |
if [ "$filenew" != "$file" ] | |
then | |
mv $file $filenew | |
echo "$file was moved to $filenew" | |
fi | |
fooCount=$(grep -c foo $filenew) | |
if [ "$fooCount" -ne "0" ] | |
then | |
sed -i 's/foo/bar/g' $filenew | |
echo "Change $filenew in $fooCount places" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment