我有一个日志文件,条目如下:
... 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命令行工具对每个行中的时间戳进行排序?
解决方法
使用
sort的-k标志:
sort -k1 -r freeswitch.log
这将按照第一个键(即freeswitch.log:2011-09-08 12:21:07.282236)对文件进行排序.如果文件名总是相同的(freeswitch.log),那么它应该按日期排序.