I'm having an issue sorting a file (badsort.small) containing these lines:
0 foo 30
0 foo/bar 26
0 foo/bar 2b
0 foo/bar 30
0 foo/bar 73
0 foo/bar 91
0 foo/bar d3
The following sort gives odd results:
sort -nk1,1 -k2,2 -k3,3 badsort.small
0 foo/bar d3
0 foo/bar 2b
0 foo/bar 26
0 foo 30
0 foo/bar 30
0 foo/bar 73
0 foo/bar 91
which is equivalent to sort -nk3,3. These commands sort correctly:
- sort -k1,1 -k2,2 -k3,3
- sort -nk1,1 -k2,3
- sort -k2,2 -k3,3
What is it about this request that causes the wrong argument to turn numeric and prevail? Is there a way to avoid it? I'm generating sort args programmatically and though I can combine adjacent fields in this case I'm not confident I won't run into this again.
Reproduced on linux 3.2.0-70-generic and on osx 10.9.5.