Skip to content

Instantly share code, notes, and snippets.

@ahk
Created May 3, 2011 18:41
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 ahk/953932 to your computer and use it in GitHub Desktop.
Save ahk/953932 to your computer and use it in GitHub Desktop.
find and replace strings in glob
# $@ and $* are the same without quotes, but with quotes
# $* is one quoted string containing all args, $@ is one quoted string
# for each arg. This handles spaces in filenames correctly.
FINDSTR=${1};
REPSTR=${2};
shift;
shift;
echo "replace ${FINDSTR} with ${REPSTR} in" "$@"
for FN in "$@"
do
ruby -p -i -e "gsub('${FINDSTR}', '${REPSTR}')" "${FN}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment