Created
April 5, 2019 02:37
-
-
Save nyaocat/3abd9881b69b84b134c4a141672d56e1 to your computer and use it in GitHub Desktop.
grep した結果に対してのみ編集を行うコマンド(例: grepedit -E '^[1-9]' * )
This file contains 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/bash | |
set -eu | |
BUF="$(mktemp)" | |
trap "rm '$BUF'" 0 | |
grep -H -n "$@" > "$BUF" | |
"${EDITOR:-vi}" "$BUF" | |
IFS=":" | |
while read file n body | |
do | |
sed -i -e "${n}i ${body}" -e "${n}d" "$file" | |
done < "$BUF" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment