Unix 版本号 [英] Unix sort of version numbers

查看:49
本文介绍了Unix 版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个版本号列表,例如它们在一个文件 versions.txt 中

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

我尝试过使用k"参数使用各种排序命令,但并没有真正理解它以将其实现.任何帮助,将不胜感激.

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.

推荐答案

-V 选项是最好的,但我想远离安装新的/其他软件,因为我的排序没有有那个选项.

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

来自评论:

  • 颠倒顺序: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

这篇关于Unix 版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆