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

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.125.0. UTC+08:00, 2024-05-04 17:43
浙ICP备14020137号-1 $访客地图$