1

I want that line from the file which have highest length among all the lines using awk command.

Hauke Laging
  • 90,279
Shah Honey
  • 74
  • 4

2 Answers2

0
awk '{ if (length($0)>maxlength) { maxlength=length($0); longest_line=$0; } };
     END { print longest_line; }' inputfile
Hauke Laging
  • 90,279
0

Check length of line (if no arguments passed to the length function it uses $0, the whole line).

Where length is greater than variable x, set x to the length. And set variable a to the contents of the line.

Finally, on reaching end of file, print the contents of variable a.

awk 'length>x{x=length;a=$0}END{print a}' inputfile

Try it online!

steve
  • 21,892