4

文件清单:

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...

4

2 回答 2

5

按更多列排序:

sort -t- -k5,5 -k7n

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

于 2013-04-30T11:30:49.317 回答
4

for循环是完全没有必要的,就像管道输出时的参数一样-1ls这产生

ls -A | sort -t- -k 5,5 -k 7,7n

其中第一个键在第 5 列开始和结束,第二个键在第 7 列开始和结束,并且是数字。

于 2013-04-30T11:50:44.663 回答