Skip to content

Instantly share code, notes, and snippets.

@clinuz
Created February 13, 2012 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clinuz/1817671 to your computer and use it in GitHub Desktop.
Save clinuz/1817671 to your computer and use it in GitHub Desktop.
Search and replace example...
#!/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