Skip to content

Instantly share code, notes, and snippets.

@cls cls/git-sed.sh
Created Mar 25, 2018

Embed
What would you like to do?
Execute sed substitution expression over files in a git tree
#!/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
You can’t perform that action at this time.