2

我希望首先列出基于文件名日期和时间戳的目录中最旧的文件。

例子:

输入文件 :

AAAG11020709581.txt
AAAG13020709581.txt
AACL11020709581.txt
AACL13020709581.txt
AAFU11020709581.txt
AAFU13020709581.txt
AAHO11020709581.txt
AAHO13020709581.txt
AAPC11020709581.txt
AAPC13020709581.txt
AAPO11020709581.txt
AAPO13020709581.txt
AATR11020709581.txt
AATR13020709581.txt
AARC11020709581.txt
AARC13020709581.txt

预期输出:

AAAG11020709581.txt
AACL11020709581.txt
AAFU11020709581.txt
AAHO11020709581.txt
AAPC11020709581.txt
AAPO11020709581.txt
AARC11020709581.txt
AATR11020709581.txt
AAAG13020709581.txt
AACL13020709581.txt
AAFU13020709581.txt
AAHO13020709581.txt
AAPC13020709581.txt
AAPO13020709581.txt
AARC13020709581.txt
AATR13020709581.txt

有人可以建议吗?

4

1 回答 1

5

默认情况下,排序将以行的开头作为键进行排序。你可以用符号告诉它从不同的地方-k FIELD.OFFSET开始,例如,如果所有文件名都以 4 个字母开头,你可以像这样跳过这些:

sort -k1.5

输出:

AAAG11020709581.txt
AACL11020709581.txt
AAFU11020709581.txt
AAHO11020709581.txt
AAPC11020709581.txt
AAPO11020709581.txt
AARC11020709581.txt
AATR11020709581.txt
AAAG13020709581.txt
AACL13020709581.txt
AAFU13020709581.txt
AAHO13020709581.txt
AAPC13020709581.txt
AAPO13020709581.txt
AARC13020709581.txt
AATR13020709581.txt
于 2013-04-03T12:25:23.243 回答