gpt4 book ai didi

bash - 多字段和数字排序

转载 作者:行者123 更新时间:2023-11-29 09:09:11 25 4
gpt4 key购买 nike

文件列表:

sysbench-size-256M-mode-rndrd-threads-1
sysbench-size-256M-mode-rndrd-threads-16
sysbench-size-256M-mode-rndrd-threads-4
sysbench-size-256M-mode-rndrd-threads-8
sysbench-size-256M-mode-rndrw-threads-1
sysbench-size-256M-mode-rndrw-threads-16
sysbench-size-256M-mode-rndrw-threads-4
sysbench-size-256M-mode-rndrw-threads-8
sysbench-size-256M-mode-rndwr-threads-1
sysbench-size-256M-mode-rndwr-threads-16
sysbench-size-256M-mode-rndwr-threads-4
sysbench-size-256M-mode-rndwr-threads-8
sysbench-size-256M-mode-seqrd-threads-1
sysbench-size-256M-mode-seqrd-threads-16
sysbench-size-256M-mode-seqrd-threads-4
sysbench-size-256M-mode-seqrd-threads-8
sysbench-size-256M-mode-seqwr-threads-1
sysbench-size-256M-mode-seqwr-threads-16
sysbench-size-256M-mode-seqwr-threads-4
sysbench-size-256M-mode-seqwr-threads-8

我想按模式(rndrd、rndwr 等)对它们进行排序,然后按编号排序:

sysbench-size-256M-mode-rndrd-threads-1
sysbench-size-256M-mode-rndrd-threads-4
sysbench-size-256M-mode-rndrd-threads-8
sysbench-size-256M-mode-rndrd-threads-16
sysbench-size-256M-mode-rndrw-threads-1
sysbench-size-256M-mode-rndrw-threads-4
sysbench-size-256M-mode-rndrw-threads-8
sysbench-size-256M-mode-rndrw-threads-16
....

我试过下面的循环,但它是按数字排序的,但我需要像 1,4,8,16 这样的序列:

$ for f in $(ls -1A); do echo $f; done | sort -t '-' -k 7n

编辑:

请注意,数字排序 (-n) 按数字 (1,1,1,1,4,4,4,4...) 排序,但我需要像 1,4,8,16,1 这样的序列,4,8,16...

最佳答案

按更多列排序:

sort -t- -k5,5 -k7n

主要排序是按第 5 列(而不是其余列,这就是 5,5 的原因),按第 7 列中的数字进行二次排序。

关于bash - 多字段和数字排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16298751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com