grep 大于指定日期的行,grep日志文件大于时间戳

I have a unix log file(application.log), that has logs with timestamp at the starting. I need to search for a pattern "sent" in this log file greater than time 2014-03-20 14:05:54.

2014-03-20 14:05:54,038 [NfxAgent....

2014-03-20 14:05:54,164 [NfxAgent....

2014-03-20 14:05:54,298 [NfxAgent....

2014-03-20 14:05:54,414 [NfxAgent....

2014-03-20 14:05:54,787 [NfxAgent....

解决方案

I added 2 more records to the test data to ensure this is really working:

2014-03-19 14:05:53,999 [NfxAgent....

2014-03-20 14:05:53,164 [NfxAgent....

But I don't think you can use grep for this. Here is an awk solution:

$ grep sent grepTest_20140321.txt| awk '$0 > "2014-03-20 14:05:54"'

2014-03-20 14:05:54,038 [NfxAgent....

2014-03-20 14:05:54,164 [NfxAgent....

2014-03-20 14:05:54,298 [NfxAgent....

2014-03-20 14:05:54,414 [NfxAgent....

2014-03-20 14:05:54,787 [NfxAgent....

edit

"What if we need to specify the end time in the same format like 2014-03-21 10:04:14,018?"

And I've added 3 lines of test data to confirm the 2nd case:

2014-03-21 10:04:14,017 [NfxAgent....

2014-03-21 10:04:14,018 [NfxAgent....

2014-03-22 10:04:14,999 [NfxAgent....

Result shows one new record in the range you've specified.

x000294@nardhl011 1220>awk '$0 ~ "sent" && $0 > "2014-03-20 14:05:54" && $0 < "2014-03-21 10:04:14,018"' grepTest_20140321.txt

2014-03-20 14:05:54,038 [NfxAgent....

2014-03-20 14:05:54,164 [NfxAgent....

2014-03-20 14:05:54,298 [NfxAgent....

2014-03-20 14:05:54,414 [NfxAgent....

2014-03-20 14:05:54,787 [NfxAgent....

2014-03-21 10:04:14,017 [NfxAgent....

IHTH

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值