Longest line using awk

情到浓时终转凉″ 提交于 2020-01-11 03:14:27

问题


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

Thanks


回答1:


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



回答2:


awk '{ if (length($0) > longest) longest = length($0); } END { print longest }'


来源:https://stackoverflow.com/questions/12607776/longest-line-using-awk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!