如何从具有当前日期的日志文件中grep行? [英] How to grep lines from a log file that have the current date?
本文介绍了如何从具有当前日期的日志文件中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
。 / p>
I am looking for a sepcific
EmpID
in the logs with current date.
然后通过管道传输到另一个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屋!
查看全文