#!/usr/bin/env python3 """Prints only the [security] items of a numbered review list.""" import re, sys items, cur = [], None for line in open(sys.argv[1]).read().splitlines(): if re.match(r"\s*\d+\.\s+", line): cur = [line]; items.append(cur) elif cur is not None: cur.append(line) print("\n".join("\n".join(i) for i in items if re.match(r"\s*\d+\.\s+\[security\]", i[0])))