Skip to content

Instantly share code, notes, and snippets.

@BillyDonahue
Last active October 20, 2020 07:21
Show Gist options
  • Save BillyDonahue/65cc418b5e6235adbf97fe61d4c3a0f9 to your computer and use it in GitHub Desktop.
Save BillyDonahue/65cc418b5e6235adbf97fe61d4c3a0f9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# $ sed_grep_results.sh cmd
#
# Apply the sed command `cmd` to every file:line: specified on stdin.
# Example:
#
# git grep -n '\<IsMasterOutcome\>' | sed_grep_results.sh 's/IsMasterOutcome/HelloOutcome/g'
#
sed_command="$1"
while read hit
do
file="$(cut -d: -f1 <<< "${hit}")"
line="$(cut -d: -f2 <<< "${hit}")"
echo "{file:\"${file}\",line:${line}}"
sed -i.orig "$file" -e "${line} ${sed_command}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment