Reputation: 368
We can get the length of the longest line and order number with command:
awk '{ print length(), NR, $0 | "sort -rn" }' /tmp/test.txt |head -n 1
Now ,to open /tmp/test.txt with command vim.
:!awk '{ print length(), NR, $0 | "sort -rn" }' % |head -n 1
Press ENTER or type command to continue
head: cannot open ‘n’ for reading: No such file or directory
head: cannot open ‘1’ for reading: No such file or directory
sort: fflush failed: standard output: Broken pipe
sort: write error
How to fix it?
Upvotes: 0
Views: 483
Reputation: 3363
Your command is quite inefficient. If you are using awk
anyway, you should also let it calculate the length of the longest line:
awk '{ l = length($0); a = (a > l) ? a : l } END {print a}' test.txt
Upvotes: 1