Skip to content

Instantly share code, notes, and snippets.

@rainbow23
Last active October 9, 2025 10:01
Show Gist options
  • Select an option

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

Select an option

Save rainbow23/e412698ee26f55622d5c2efac150e133 to your computer and use it in GitHub Desktop.
# pack_blocks_utf8bom.awk
# 目的:
# - ブロックを1セル(1フィールド)のCSVとして出力(ブロック内改行はそのまま)
# - 区切りは次のどちらかの行が出た時点:
# 1) 行頭が "Change-Id:"
# 2) 行頭が "Merge" かつ 行末が "into car-apps-dev"
#
# メモ:
# - 出力はUTF-8(BOM付き) -> Windows版Excelで文字化けしにくい
# - ダブルクォートは CSV 仕様に合わせて "" にエスケープ
BEGIN {
# UTF-8 BOM(Excel対策)
printf "\xEF\xBB\xBF"
pat_change = "^Change-Id:[[:space:]]*"
pat_merge = "^Merge.*into[[:space:]]+car-apps-dev[[:space:]]*$"
}
{
# 行をそのまま蓄積(空行も含む)
buf = (buf == "" ? $0 : buf ORS $0)
# 区切り条件: Change-Id か、Merge...into car-apps-dev
if ($0 ~ pat_change || $0 ~ pat_merge) {
out = buf
gsub(/"/, "\"\"", out) # " -> ""
print "\"" out "\"" # 1フィールドCSVとして出力
buf = "" # リセット
}
}
END {
# 末尾に未完ブロックが残っている場合、通常は出さない。
# 必要なら次の3行のコメントアウトを外してください。
# if (buf != "") {
# out = buf; gsub(/"/, "\"\"", out); print "\"" out "\""
# }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment