Skip to content

Instantly share code, notes, and snippets.

@rainbow23
Created September 30, 2025 05:03
Show Gist options
  • Select an option

  • Save rainbow23/6c6e27e71745577cc0ce7c4587b5f559 to your computer and use it in GitHub Desktop.

Select an option

Save rainbow23/6c6e27e71745577cc0ce7c4587b5f559 to your computer and use it in GitHub Desktop.
awk '
BEGIN{ g=0; inblk=0 }
# TARGET 行(コミットID抽出)
/^TARGET/ {
# 40桁のGitハッシュ想定。必要に応じて [0-9a-f]{40} を緩めてもOK。
if (match($0, /[0-9a-f]{40}/, m)) {
if (!inblk) { g++; inblk=1; first[g]=""; last[g]="" }
if (first[g]=="") first[g]=m[0]; # ブロックの先頭(新しい側)
last[g]=m[0]; # 常に更新→最後に見えた(古い側)
}
next
}
# NO_TARGET 行でブロック終端
/^NO_TARGET/ {
if (inblk) {
# 出力形式: BLOCK <index> <first> <last>
printf("BLOCK %d %s %s\n", g, first[g], last[g]);
inblk=0
}
next
}
# その他の行は無視
{ next }
# 末尾がTARGETで終わってNO_TARGETが来ないケースの保険
END{
if (inblk && first[g] != "" && last[g] != "") {
printf("BLOCK %d %s %s\n", g, first[g], last[g]);
}
}
' hoge.log > blocks.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment