Created
February 13, 2012 15:38
-
-
Save clinuz/1817671 to your computer and use it in GitHub Desktop.
Search and replace example...
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 | |
# example... | |
# sed -E "s/SC.(TableColumn|TableView)/EO.\1/g" $x > tmpfile | |
# expect 2 args, first is the one to find, second to replace | |
if [ $# -lt 2 ] | |
then | |
echo "You must pass 2 arguments. The first to 'find' and the second to 'replace'" | |
exit | |
fi | |
# assign the values for clarity | |
FIND=$1 | |
REPLACE=$2 | |
DEBUG=$3 | |
echo "Searching for '$FIND' and will replace with '$REPLACE'" | |
echo "Starting to search and replace..." | |
for x in `find ./* -name '*.js'` | |
do | |
sed -E "s/$FIND/$REPLACE/g" $x > tmpfile | |
if [ "$DEBUG" ] | |
then | |
cat tmpfile | |
else | |
cat tmpfile > $x | |
fi | |
done | |
rm tmpfile | |
echo "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment