解析日期文件中包含日期时间大于某些内容的行 [英] Parsing lines from a log file containing date-time greater than something

查看:141
本文介绍了解析日期文件中包含日期时间大于某些内容的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大小为几百MB大小的日志文件,包含这样的行,包含开头的日期 - 时间信息:

  [Tue Oct 4 11:55:19 2016] [hphp] [25376:7f5d57bff700:279809:000001] [] \\\
Fatal error:syntax error,unexpected T_ENCAPSED_AND_WHITESPACE,expected')'in / var / cake_1.2.0.6311-beta / app / webroot / openx / www / delivery / postGetAd.php(12479)(62110d90541a84df30dd077ee953e47c):第1行的eval()'代码
pre>

我有一个插件(nagios check_logwarn)只打印出包含一些错误字符串的行。以下是运行它的命令:

  / usr / local / nagios / libexec / check_logwarn -d / tmp / logwarn -p /mnt/log/hiphop/error_20161003.log^。*致命错误*

我想根据日期时间进一步过滤,即所有在11:55:10之后的行。

我不知道是否使用正则表达式。以下是我到目前为止:

pre $ us $ local / nagios / libexec / check_logwarn -d / tmp / logwarn -p /mnt/log/hiphop/error_20161003.log^。*致命错误*| grep15 \:19 \:1 *

但这只会过滤那些日志时间是在15小时的第19分钟。

更新



现在我可以比较日期的时间部分-时间。

  / usr / local / nagios / libexec / check_logwarn -d / tmp / logwarn -p / mnt / log / hiphop / error_20161004 .log^。*致命错误*| awk'$ 4> 14:22:11'

我如何比较每日部分?



更新2 - 打开赏金

我不得不开一个赏金,因为我没有太多我很快就需要一个解决方案。



我被困在比较日期的部分。通过解决方案 https://stackoverflow.com/a/39856560/351903 ,我正面临这个问题。如果这是固定的,我会很高兴。



我也对此进行了一些改进(我不介意输出的日志顺序是否混乱) -

  / usr / local / nagios / libexec / check_logwarn -d / tmp / logwarn -p /mnt/log/hiphop/error_20161004.log^。*致命错误*| awk'$ 4> 14:22:11'

我寻找一些日期时间来比较时间戳,找不到工作。



我无法从这个问题。我看不到使用此时间戳记的价值 - $ / b>

  echo date -d '06 / 12/2012 07:21:22'+ %s

不知道我错过了什么。

它使用参考时间戳并比较日志文件的时间戳与它;如果日志文件的时间戳更近,则打印该行:

awk -v refdate =$(date +'%s'-d'Mon Oct 3 10:00:00 2016')-F[] []'
{
cmd =date + \ ((cmd | getline val)> 0){
if(val> refdate)
打印
}
关闭(cmd)
}
'infile

以下是它的工作方式:

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