Sorting stops working when adding `-k 2`

I have a file that I want to be sorted by number. Largest number on the end.

Why is this second option working, or why is the first option not working ?

9.7.2
9.7
8.4.11
8.4
9.7.1
8.4.10
9.7.0
8.4.9
8.0.46
8.0
9.6.0
9.6
8.4.8
8.0.45
9.5.0
9.5
8.4.7
8.0.44
9.4.0
9.4
8.4.6
8.0.43

First option, sorting by column 1,2 and 3, using the -k option, and numerically using the -n option:

sort -n -k 1 -k 2 -k 3 -t "." file
8.0
8.0.43
8.0.44
8.0.45
8.0.46
8.4
8.4.10
8.4.11
8.4.6
8.4.7
8.4.8
8.4.9
9.4
9.4.0
9.5
9.5.0
9.6
9.6.0
9.7
9.7.0
9.7.1
9.7.2

As seen the .10 and .11 are in the wrong order, because I would expect them to be after .9.

Second option:

sort -n -k 1 -k 3 -t "." file
8.0
8.0.43
8.0.44
8.0.45
8.0.46
8.4
8.4.6
8.4.7
8.4.8
8.4.9
8.4.10
8.4.11
9.4
9.4.0
9.5
9.5.0
9.6
9.6.0
9.7
9.7.0
9.7.1
9.7.2

sort --version sort (uutils coreutils) 0.11.0

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论