一尘不染

在Linux命令行上按时间戳排序日志文件

linux

我有一个日志文件,其中包含:

...    
freeswitch.log:2011-09-08 12:21:07.282236 [ERR] ftdm_queue.c:136 Failed to enqueue obj 0x7f2cda3525c0 in queue 0x7f2ce8005990, no more room! windex == rindex == 58!
freeswitch.log:2011-08-08 13:21:07.514261 [ERR] ftdm_queue.c:136 Failed to enqueue obj 0x7f2cda354460 in queue 0x7f2ce8005990, no more room! windex == rindex == 58!
freeswitch.log:2011-06-04 16:21:08.998227 [ERR] ftdm_queue.c:136 Failed to enqueue obj 0x7f2cda356300 in queue 0x7f2ce8005990, no more room! windex == rindex == 58! 
freeswitch.log:2011-09-08 12:21:10.374238 [ERR] ftdm_queue.c:136 Failed to enqueue obj 0x7f2cda3581a0 in queue 0x7f2ce8005990, no more room! windex == rindex == 58!
...

如何使用linux命令行工具按每行的时间戳降序对文件排序?


阅读 700

收藏
2020-06-03

共1个答案

一尘不染

使用sort的-k标志:

sort -k1 -r freeswitch.log

这将通过第一个键对文件进行反向排序(即freeswitch.log:2011-09-08
12:21:07.282236)。如果文件名始终相同(freeswitch.log),则应按日期排序。

2020-06-03