I want to sort a space separated tableby a numeric value that was found in the second field. I can assume that the second field is always fooN, but the length of N is unknown:
antiq. foo11 girls
colleaguing foo2 Leinsdorf
Cousy foo0 Montgomeryville
bowlegged foo1 pollack
Chevrier foo10 ill-conceived
candlebomb foo3 seventieths
autochthony foo101 re-enable
beneficiate foo100 osteometric
I read man sort(1)and played with all the parameters. On my system, I found the line:
sort -n -k2.5 table
for work.
My question is why?
According to the manual page:
-k,
start a key at POS1, end it at POS 2 (origin 1)
...
POS is F[.C][OPTS], where F is the field number and C the characterposition in the
field. OPTS is one or more single-letter ordering options, which override global
ordering options for that key. If no key is given, use the entire line as the key.
So why does the table sort -n -k2.4not work and sort -n -k2.5do?
source
share