Grep具有当前日期的日志文件 [英] Grep a log file with current date

查看:527
本文介绍了Grep具有当前日期的日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要grep一个带有今天日期的日志文件.但是显示的输出超出了今天的日期.

I need to grep a log file with today's date. But the output is showing for more than today's date.

grep date +"20%y-%m-%d" /path/log/General.log | grep "EmpID#106496" /path/log/Genral.log

输出:

2013-06-19 14:47:05,996 - INFO  EmpID#106496 
2013-06-19 14:47:05,996 - INFO  EmpID#106496 
2013-06-21 00:01:24,915 - INFO  EmpID#106496 
2013-06-21 00:01:24,915 - INFO EmpID#106496  

推荐答案

只需将date输出用作grep中的模式:

Just use the date output as a pattern in grep:

$ grep "$(date +"%Y-%m-%d")" file
2013-06-21 00:01:24,915 - INFO   
2013-06-21 00:01:24,915 - INFO

也就是说,您需要将date句子括起来以使其得到处理.另外,请注意,我使用的是Y而不是您的20%y.

That is, you need to enclose the date sentence to make it be processed. Also, note I used Y instead of your 20%y.

我正在使用当前日期的日志中寻找一个单独的EmpID.

然后通过管道传输到另一个grep:

Then pipe to another grep:

$ grep $(date +"%Y-%m-%d") file | grep "EmpID#106496"
2013-06-21 00:01:24,915 - INFO  EmpID#106496 
2013-06-21 00:01:24,915 - INFO EmpID#106496 

这篇关于Grep具有当前日期的日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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