Created
March 25, 2018 18:29
-
-
Save cls/87cf0f1219be89b60af5ffcde8ce54c9 to your computer and use it in GitHub Desktop.
Execute sed substitution expression over files in a git tree
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
| #!/bin/sh | |
| expr="$1" | |
| shift | |
| pattern="$(printf "%s" "$expr" | sed -n 's/^s\/\(\([^\\\/]\|\\.\)*\)\/\([^\\\/]\|\\.\)*\/g\?$/\1/p')" | |
| if [ -z "$pattern" ] | |
| then | |
| printf "usage: git sed s/lhs/rhs/[g] [file...]\n" > /dev/stderr | |
| exit 2 | |
| fi | |
| git grep -I -l -z "$pattern" "$@" | xargs -0 sed -i "$expr" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment