Longest line in a file

前端 未结 14 2086
鱼传尺愫
鱼传尺愫 2020-11-27 10:34

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.

14条回答
  •  爱一瞬间的悲伤
    2020-11-27 11:24

    Looks all the answer do not give the line number of the longest line. Following command can give the line number and roughly length:

    $ cat -n test.txt | awk '{print "longest_line_number: " $1 " length_with_line_number: " length}' | sort -k4 -nr | head -3
    longest_line_number: 3 length_with_line_number: 13
    longest_line_number: 4 length_with_line_number: 12
    longest_line_number: 2 length_with_line_number: 11
    

提交回复
热议问题