Unix的版本号 [英] Unix sort of version numbers
本文介绍了Unix的版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个版本号列表,例如,假设它们位于文件versions.txt中.
1.2.100.4
1.2.3.4
10.1.2.3
9.1.2.3
我希望对它们进行排序,以便按版本对它们进行排序.即:
1.2.3.4
1.2.100.4
9.1.2.3
10.1.2.3
我尝试使用各种使用"k"参数的排序命令,但对它的理解并不足够好,无法完成.任何帮助,将不胜感激.
解决方案
-V
选项是最好的,但是我想避免安装新的/其他软件,因为我的排序没有该选项. >
这是最终对我有用的命令:
sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n test.txt
来自评论:
- 要颠倒顺序:
sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr
- 要跳过
v
前缀:sort -t. -k 1.2,1n -k 2,2n -k 3,3n -k 4,4n
I have a list of version numbers, let's say for instance that they are in a file versions.txt
1.2.100.4
1.2.3.4
10.1.2.3
9.1.2.3
I wish to sort them so that they are sorted by version. i.e:
1.2.3.4
1.2.100.4
9.1.2.3
10.1.2.3
I have tried using various sort commands using the "k" parameters, but do not really understand it well enough to pull it off. Any help would be appreciated.
解决方案
The -V
option is the nicest, but I wanted to stay away from installing new/other software since my sort didn’t have that option.
This is the command that worked for me in the end:
sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n test.txt
From comments:
- To reverse the order:
sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr
- To skip the
v
prefix:sort -t. -k 1.2,1n -k 2,2n -k 3,3n -k 4,4n
这篇关于Unix的版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文