Longest line in a file

前端 未结 14 2114
鱼传尺愫
鱼传尺愫 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:10

    Variation on the theme.

    This one will show all lines having the length of the longest line found in the file, retaining the order they appear in the source.

    FILE=myfile grep `tr -c "\n" "." < $FILE | sort | tail -1` $FILE
    

    So myfile

    x
    mn
    xyz
    123
    abc
    

    will give

    xyz
    123
    abc
    

提交回复
热议问题