我该如何排序文件通过版本号的名字呢? [英] How can I sort file names by version numbers?

查看:172
本文介绍了我该如何排序文件通过版本号的名字呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在目录中的数据是这些文件:

In the directory "data" are these files:

命令1.9A-设置结果
  命令2.0A-设置结果
  命令2.0C-设置结果
  命令2.0设置

command-1.9a-setup
command-2.0a-setup
command-2.0c-setup
command-2.0-setup

我想对文件进行排序,以得到这样的结果:

I would like to sort the files to get this result:

命令1.9A-设置结果
  命令-2.0-设置结果
  命令2.0A-设置结果
  命令2.0C-设置

command-1.9a-setup
command-2.0-setup
command-2.0a-setup
command-2.0c-setup

这个我试过

find /data/ -name 'command-*-setup' | sort --version-sort --field-separator=- -k2 

但产量

命令1.9A-设置结果
  命令2.0A-设置结果
  命令2.0C-设置结果
  命令2.0设置

command-1.9a-setup
command-2.0a-setup
command-2.0c-setup
command-2.0-setup

我发现的唯一的方式,给了我所需的输出是

The only way I found that gave me my desired output was

tree -v /data

我怎么能得到与排序的通缉令输出?

How could I get with sort the output in the wanted order?

推荐答案

看起来是这样工作的:

find /data/ -name 'command-*-setup' | sort -t - -V -k 2,2

不排序,但它的工作原理:

not with sort but it works:

tree -ivL 1 /data/ | perl -nlE 'say if /\Acommand-[0-9][0-9a-z.]*-setup\z/'

-v:排序版本结果输出
-i:使树不打印压痕线结果
-L级别:目录树的最大显示深度

-v: sort the output by version
-i: makes tree not print the indentation lines
-L level: max display depth of the directory tree

这篇关于我该如何排序文件通过版本号的名字呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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