BEGINFILE/ENDFILE vs. FNR==1: Choosing Per‑File State Logic in Awk
Goal Implement per‑file counters and summaries in an awk script that processes many input files. Constraint The script must run on a variety of Unix-like systems where the default awk may be POSIX awk, mawk, BusyBox awk, or gawk. The choice of per‑file logic affects portability, readability, and error handling. Uncertainty While the FNR==1 idiom works everyw