if a file contains multiple columns, seperated by comma, like this:
aaa,1,4,4,5,7
bbb,1,4,9,1,2
Is there difference between ‘sort -t, -k1 file.txt’ and ‘sort -t, -k1,1 file.txt’?
though with the example above, there is no difference, but in some of my project case, it
does has difference, but the difference is reflected in the case that I use the sorted file to join, and the join command throws out exception that ‘join: file 2 is not in sorted order’ (at that time , I use ‘sort -t, -k1 file.txt’) . Later I use ‘sort -t, -k1,1 file.txt’, and join command works well then. Can anybody tell me why?
sort -k1means sort starting on key 1 till the end of the line.sort -k1,1means sort from key 1 to key 1 (so only the first key). On my machine, the two make a difference if I specify stable sort with-s: