Count the number of characters (or columns) in a file

Sometimes you want to count the number of characters or columns in a file.

awk 'length>max{max=length}END{print max}' filename.txt

For extraordinarily long or wide data sets you may want to consider the following:

head -n 10 | awk 'length>max{max=length}END{print max}'

OR

tail -n 10 | awk 'length>max{max=length}END{print max}'