Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Like GNU awk's BEGINFILE/ENDFILE but works with any awk(1)
- # NB: Named beginfile()/endfile() to prevent conflict with GNU awk
- #
- function beginfile(file) {
- numlines = FNR == 0 ? 0 : 1 # to simulate `wc -l'
- }
- function endfile(file) {
- printf "%8u %s\n", numlines, file # to simulate `wc -l'
- }
- { numlines++ } # to simulate `wc -l'
- # Cross-platform compatible implementation of GNU awk's BEGINFILE/ENDFILE
- NR == 1 { beginfile(file = FILENAME) }
- FNR != NR {
- FNR = NR
- endfile(file)
- beginfile(file = FILENAME)
- }
- END {
- endfile(file)
- printf "%8u total\n", FNR # to simulate `wc -l'
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement