Issue
I'm listing the number of words in a bunch of files and sorting it like this:
wc -w *.tex | sort -rn
which outputs a nice list of the files and word count for each file
17423 total
6481 panama-to-colombia.tex
5516 the-salt-flats.tex
5426 hiking-cordillera-huayhuash.tex
How can I also calculate and display the average number of words per file? i.e. a line at the bottom like:
5808 AVERAGE
Note: I'd like to find a solution that works for an arbitrary number of files in the list.
Solution
I suggest to append to your code:
| awk '{sum=sum+$1; print};END{print sum/2/(NR-1),"AVERAGE"}'
Answered By - Cyrus Answer Checked By - Senaida (WPSolving Volunteer)