1

Using bash, how can I get the longest line in a file?

$ cat file
12
3241234
123
3775
874
62693289429834
8772168376123

I want to get 62693289429834.

Yishu Fang
  • 9,448
  • 21
  • 65
  • 102

2 Answers2

2
 sort -V file | tail -n1

works on your example input. I'm not completely sure it will work on other inputs as well but I think so.

Jan Matějka
  • 1,880
  • 1
  • 14
  • 31
0
 awk ' { if ( length > x ) { x = length } }END{ print x }' file
Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130