I\'m looking for a simple way to find the length of the longest line in a file. Ideally, it would be a simple bash shell command instead of a script.
perl -ne 'print length()." line $. $_"' myfile | sort -nr | head -n 1
Prints the length, line number, and contents of the longest line
perl -ne 'print length()." line $. $_"' myfile | sort -n
Prints a sorted list of all lines, with line numbers and lengths
. is the concatenation operator - it is used here after length()
$. is the current line number
$_ is the current line