14:33:55 anthony:~$ echo -e "1\ta\n10\tb\n20\tc\n2\td" | sort -k1,1
1 a
10 b
2 d
20 c
14:33:56 anthony:~$ echo -e "1\ta\n10\tb\n20\tc\n2\td" | sort -k1
10 b
1 a
20 c
2 d
14:33:56 anthony:~$
Because in the second sort where you say that the key is one character long, the sort program does not necessarily maintain keys that are equal on a fifo basis.
Hi vgersh99,
Thanks but I actually want a sort based on the string values. I try to understand that 2nd output as it's a mystery to me!
Jgt,
wait i'm not sure I understand. i thought -kX1,Y1 -kX2, Y2... meant that the sort were to happen on field X1 to Y1 and to X2 to Y2. Does it have to do with the position of CHARACTER, not field??
Can you modify your input data, maybe you have already saved the unsorted file to disk.
Change the tmp25 file so that the file actually is
10<tab>a
1<sp><tab>b
20<tab>c
2<sp><tab>d
Where <sp> is space and <tab> is tab.
It may be that your sort program is restricting the length of key1 to the shortest key 1.
ok I got it, i misunderstood "-k1". I thought it meant -k1[,1], that default for POS2 was same as POS1, when actually it means -k1,n where n is the last field. And since 10 < 1\\t, it all make sense.
Thanks everyone for trying to help though!
jgt is mistaken. neither of your sort commands specify a one character key. -k1,1 specifies the first field. -k1 specifies the first field through to the last character in the line.