-
-
Save joscha/5759014 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function substitute { | |
if [ -z "$1" -o -z "$2" ]; then | |
echo "Usage: substitue FROM_STRING TO_STRING [OPTION]..." | |
echo | |
echo "Replace all occurances of FROM_STRING (a sed-compatible regular" | |
echo "expression) with TO_STRING in all files for which ack-grep matches" | |
echo "FROM_STRING." | |
echo | |
echo "Any additional options are passed directly to ack-grep (e.g.," | |
echo " --type=html would only run the substitution on html files)." | |
return 1 | |
fi | |
# Escape forward slashes for sed | |
FROM_STRING=${1//\//\\/} | |
TO_STRING=${2//\//\\/} | |
shift 2 | |
ack -l --print0 "$@" "$FROM_STRING" | xargs -0 -n 1 sed -i -e "s/$FROM_STRING/$TO_STRING/g" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed line 14 & 15 to escape all occurences of / not only the first one
and changed ack-grep to ack