在日志文件中搜索并打印特定日期
我正在处理一个日志文件,我想打印从特定日期到结束的信息。例如,该特定日期是 ($sd=27/Dec/2002)。现在我想搜索这一天并从中打印直到日志文件末尾!但如果 27/Dec 不在日志文件中的项目中怎么办?它应该搜索 items >= $sd (27/Dec) ,我该怎么做?
这段代码只是搜索 $Sd ,即 27/Dec/2002 ,我想搜索项目 >= $sd
sed -n "$(awk '/'$sd'/ {print NR}' serverlog.log.log | head -1),$ p" serveerlog.log|cut -d: -f1
日志文件示例:
213.64.237.213 - - [23/Dec/2002:03:02:22 +0100]
213.132.36.66 - - [28/Dec/2002:19:33:29 +0100]
并且日志文件已排序!
I'm working with a log file and I want to print from a specific day till the end of it . that specific date is ($sd=27/Dec/2002) for example. now I want to search for this day and print from it till the end of log file ! but what if 27/Dec is not among items in log file ? it should search for items >= $sd (27/Dec) , how could I do this?
this code just search for $Sd which is 27/Dec/2002 , I want to search for items >= $sd
sed -n "$(awk '/'$sd'/ {print NR}' serverlog.log.log | head -1),$ p" serveerlog.log|cut -d: -f1
example of log file :
213.64.237.213 - - [23/Dec/2002:03:02:22 +0100]
213.132.36.66 - - [28/Dec/2002:19:33:29 +0100]
and the log file is sorted !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用 awk 就很容易了。请参阅下面的示例:
输出
更新
尝试此 awk 行: $sd 是变量。希望它对你有用。
it would be very easy with awk. see the example below:
output
update
try this awk line: $sd is the variable. hope that it would work for you.