编写一个 bash 脚本来比较两个日志文件的时间戳
在比较时间戳时,我无法弄清楚如何匹配以在两个不同文件中查找匹配项。我想要匹配的字段格式为:
Jul 26 09:33:02
我尝试逐行读取文件并使用 awk '{print $1,$2,$3}'
仅获取时间戳并将其存储在其中一个文件中。我环顾四周,看到了这个例子:
awk 'FNR==NR{!a[$3]++;next }{ b[$3]++ }
END {
for(i in a) {
for(k in b) {
if (a[i]==1 && i ~ k ) { print i }
}
}
}' $FILE $FILE2
哪个有效,但目前超出了我的理解范围。这两个文件可以在 /var/log/syslog 和 /var/log/auth.log (使用 Ubuntu 11.04)中找到,
我查看了其他示例,但无法将其应用到我的应用程序中。 谢谢
I'm having trouble figuring out how to match to find matches in two different files when comparing timestamps. The fields I'm wanting to match up are in the format:
Jul 26 09:33:02
I have tried reading the file line by line and usingawk '{print $1,$2,$3}'
which only gets and stores the timestamp in one of the files. I've been looking around and saw this example:
awk 'FNR==NR{!a[$3]++;next }{ b[$3]++ }
END {
for(i in a) {
for(k in b) {
if (a[i]==1 && i ~ k ) { print i }
}
}
}' $FILE $FILE2
Which sorta works but its way over my head at the moment. The two files can be found in your /var/log/syslog and /var/log/auth.log (using Ubuntu 11.04)
I looked around for other examples and wasn't able to apply it to my application.
Thank You
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设
$FILE
和$FILE2
包含时间戳列表,并且您可以以空格与其他字段分隔的方式格式化时间戳:输出将全部两个文件中都存在的时间戳。
Assuming
$FILE
and$FILE2
contain a list of timestamps and you can format the timestamp in such a way that it is separated from other fields by whitespace:The output will be all the timestamps that exist in both files.