Count line lengths in file using command line tools

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)