what is the difference between 'sort -k1 file.txt' and 'sort -k1,1 file.txt'?
sort -k1
means sort starting on key 1 till the end of the line. sort -k1,1
means 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
:
~ $ cat test.txt
aaa,1,4,4,5,7
aaa,1,3,9,1,2
~ $ sort -t, -k1 -s test.txt
aaa,1,3,9,1,2
aaa,1,4,4,5,7
~ $ sort -t, -k1,1 -s test.txt
aaa,1,4,4,5,7
aaa,1,3,9,1,2