Skip to content

Instantly share code, notes, and snippets.

@nyaocat
Created April 5, 2019 02:37
Show Gist options
  • Save nyaocat/3abd9881b69b84b134c4a141672d56e1 to your computer and use it in GitHub Desktop.
Save nyaocat/3abd9881b69b84b134c4a141672d56e1 to your computer and use it in GitHub Desktop.
grep した結果に対してのみ編集を行うコマンド(例: grepedit -E '^[1-9]' * )
#!/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