问题
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