How can I sort file names by version numbers?

前端 未结 7 1210
轮回少年
轮回少年 2020-12-05 13:23

In the directory \"data\" are these files:

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

7条回答
  •  长情又很酷
    2020-12-05 14:08

    $ cat files
    command-1.9a-setup
    command-2.0c-setup
    command-10.1-setup
    command-2.0a-setup
    command-2.0-setup
    
    $ cat files | sort -t- -k2,2 -n
    command-1.9a-setup
    command-2.0-setup
    command-2.0a-setup
    command-2.0c-setup
    command-10.1-setup
    
    $ tac files | sort -t- -k2,2 -n
    command-1.9a-setup
    command-2.0-setup
    command-2.0a-setup
    command-2.0c-setup
    command-10.1-setup
    

提交回复
热议问题