Skip to content

Instantly share code, notes, and snippets.

@dnephin
Last active January 23, 2018 19:03
Show Gist options
  • Save dnephin/a85bcc7f3c39ce258139b39cbdf960b5 to your computer and use it in GitHub Desktop.
Save dnephin/a85bcc7f3c39ce258139b39cbdf960b5 to your computer and use it in GitHub Desktop.
Bash multi-line replace t.Error; return -> t.Fatal
#!/usr/bin/env sh
set -eu -o pipefail
git grep -A 1 '\st\.Error' | \
grep 'return$' -B 2 | \
cut -f1 | \
grep -v -- '--' |
sed 's/.$//' | \
sort | \
uniq | while read filename; do
echo "$filename"
cat "$filename" | \
tr '\n' '\r' | \
sed -e 's/t.Error\([^\r]\+\)\r[[:blank:]]\+return\r/t.Fatal\1\r/g' | \
tr '\r' '\n' > t; mv t "$filename"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment