文件列表:
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 ...
答案 0 :(得分:5)
按更多列排序:
sort -t- -k5,5 -k7n
主要排序是第5列(而不是其余部分,这就是为什么5,5
),在第7列中按编号进行二次排序。
答案 1 :(得分:4)
for
循环完全没有必要,因为-1
的{{1}}参数在管道输出时是完全没有必要的。这会产生
ls
第一个键在第5列开始和结束,第二个键在第7列开始和结束,并且是数字。