This
- counts the line lengths using
awk
, then - sorts the (numeric) line lengths using
sort -n
and finally - counts the unique line length values
uniq -c
.
$ awk '{print length}' input.txt | sort -n | uniq -c
1 1
2 2
3 4
1 5
2 6
2 7
In the output, the first column is the number of lines with the given length, and the second column is the line length.