A script to change strings in the whole source tree. Use with care!

This commit is contained in:
Jeroen Baten 2014-03-26 10:47:05 +01:00 committed by Oscar Gonzalez Fernandez
parent e4b2f5783d
commit d57890ffa8

16
scripts/change-string.sh Executable file
View file

@ -0,0 +1,16 @@
#!/bin/bash
# author: J. Baten
# date: 2014-03-21
echo "Script to search for a string, find files containing it, and asks they can be changed"
read -p "Enter string to search for : " inputstring
find . -type f \( ! -iname "*.class" \) -exec grep -H "$inputstring" {} \;
echo "Done".
read -p "Do you want to replace all these strings (y/n) : " answer
if [[ ${answer,,} = 'y' ]]
then
read -p "Enter replacement string : " newstring
find . -type f \( ! -iname "*.class" \) -exec grep -l "$inputstring" {} \; | xargs sed -i -e "s/${inputstring}/${newstring}/g"
echo "Done".
fi