Reputation: 169
Can someone show, how to use awk command to identify the longest line in a text file.
Thanks
Upvotes: 4
Views: 4028
Reputation: 212654
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
Upvotes: 9
Reputation: 755054
awk '{ if (length($0) > longest) longest = length($0); } END { print longest }'
Upvotes: 2