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
  • 8,880
  • 20
  • 59
  • 100

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,769
  • 1
  • 13
  • 28
0
 awk ' { if ( length > x ) { x = length } }END{ print x }' file
Fredrik Pihl
  • 42,950
  • 7
  • 81
  • 128