sjsam sjsam - 4 months ago 25
Bash Question

Awk - print the total files processed

To print how many files were processed

awk 'FNR==1{count++}END{print count,"files processed"}' # Kinda lengthy


Is there a shorter solution available?

Also this fails if an empty files is passed? Any workarounds?

Answer

A tiny improvement, if you use GNU awk and BEGINFILE, you will handle empty files:

gawk 'BEGINFILE{print FILENAME}' *txt empty /dev/null

Output

A.txt
B.txt
s.txt
empty
/dev/null
Comments