排序日志文件通过在Linux命令行的时间戳 [英] sort logfile by timestamp on linux command line

查看:201
本文介绍了排序日志文件通过在Linux命令行的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似条目的日志文件:

I have a logfile with entries like:

...    
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!
...

我如何才能通过每一行中decending时间戳使用Linux命令行工具的文件进行排序?

How can I sort the file with linux command line tools by the timestamp in each row decending?

推荐答案

使用排序的-k标志:

sort -k1 -r freeswitch.log

这将排序的文件,在倒车时,由所述第一密钥(即freeswitch.log:2011-09-08 12:21:07.282236)。如果文件名总是相同(freeswitch.log),那么它应该通过的日期进行排序。

That will sort the file, in reverse, by the first key (i.e. freeswitch.log:2011-09-08 12:21:07.282236). If the filename is always the same (freeswitch.log), then it should sort by the date.

这篇关于排序日志文件通过在Linux命令行的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆