Longest line using awk

前端 未结 2 1543
灰色年华
灰色年华 2021-01-06 10:09

Can someone show, how to use awk command to identify the longest line in a text file.

Thanks

2条回答
  •  醉酒成梦
    2021-01-06 10:39

    To print the longest line:

    awk 'length > m { m = length; a = $0 } END { print a }' input-file
    

    To simply identify the longest line by line number:

    awk 'length > m { m = length; a = NR } END { print a }' input-file
    

提交回复
热议问题