【发布时间】:2021-02-17 17:36:22
【问题描述】:
我正在尝试按日期对文本进行排序。 我的文件格式是:
...
[15/08/2019 - 01:58:49] some text here
[15/08/2019 - 02:21:23] more text here
[15/08/2019 - 02:56:11] blah blah blah
...
我用 sort 命令尝试了多种不同的方法。
一次尝试:“sort -b --key=1n --debug Final_out.txt”
sort: using ‘en_US.UTF-8’ sorting rules
sort: key 1 is numeric and spans multiple fields
sort: option '-b' is ignored
^ no match for key
^ no match for key
...
__
.?
^ no match for key
__
.?
^ no match for key
__
sort: write failed: 'standard output': Input/output error
sort: write error
第二次尝试:“sort -n -b --key=10,11 --debug Final_out.txt” 在上面产生相同的输出
快把我的头发扯掉了。这必须是可能的,它是Linux!有没有好心人指点一下?
【问题讨论】:
-
您将不得不使用 awk 或其他东西来提取时间戳,将它们转换为可以按字典顺序排序的东西,然后将其传递给排序。