grep 返回 Trail -f httpd-access.log 中 Referer 的值

grep 返回 Trail -f httpd-access.log 中 Referer 的值

问题是:我如何httpd-access.log在使用时从文件中过滤掉http引用值tail -f /var/log/httpd-access.log

通常是请求的 url 之后的第三个值

[IP HERE] - - [09/Oct/2016:16:53:12 +0000] "[URL HERE]" 200 283 "[REFERRER_HERE << I NEED THIS ONE]" "Mozilla/5.0 (Windows NT 10.0; rv:49.0) Gecko/20100101 Firefox/49.0"

这是来自 的示例行httpd-access.log,您可以看到其中[URL HERE]哪个是真正请求的网址,两个不重要的值(对我来说),我只需要显示第三个值,

我想过 grep 但我缺乏那里的知识,可能是吗grep {something} | tail -f /var/log/httpd-access.log

谢谢。

答案1

您必须将尾部输出通过管道传递给 grep:

$ tail -F /var/log/httpd-access.log | grep 'WHATEVER'

您可以使用awk打印特定列:

$ tail -F /var/log/httpd-access.log | grep 'WHATEVER' | awk '{print $9}'

相关内容