Created
December 20, 2017 16:24
-
-
Save oleksii-zavrazhnyi/122472744905a3adb1bde8281aa206ea to your computer and use it in GitHub Desktop.
Renamer
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 | |
cat <<EOF | |
This utility will find <Search> string and replace it with <Replacement> string | |
in all files in current folder including their both filename and contents | |
EOF | |
# check if GNU rename utility exists | |
if [ ! -f /usr/local/bin/rename ] | |
then | |
echo "No GNU rename utility was found. Install it by running:" | |
echo "brew install rename" | |
fi | |
echo "Enter Search string:" | |
read FROM | |
echo "Enter Replacement string:" | |
read TO | |
echo ""; | |
echo "Renaming files..." | |
find . -iname "*${FROM}*" -exec echo "Renaming {}" \; -exec /usr/local/bin/rename s/$FROM/$TO/ {} \; | |
find . -iname "*.[m,h]" -exec echo "Replacing {}" \; -exec sed -i '' "s/${FROM}/${TO}/g" "{}" \; | |
echo "Done" | |
#EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment