Skip to content

Instantly share code, notes, and snippets.

@oleksii-zavrazhnyi
Created December 20, 2017 16:24
Show Gist options
  • Save oleksii-zavrazhnyi/122472744905a3adb1bde8281aa206ea to your computer and use it in GitHub Desktop.
Save oleksii-zavrazhnyi/122472744905a3adb1bde8281aa206ea to your computer and use it in GitHub Desktop.
Renamer
#!/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