awk-根据错误代码查找顶部网址 [英] awk - Find the top url based on error code
本文介绍了awk-根据错误代码查找顶部网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建摘要以预先分析来自我的网站的访问日志。到目前为止,我一直在使用awk获取所需的数据。
I am creating a sript to pre-analyze access logs from my website. So far I have been using awk to get desired data.
我需要能够使用awk分析顶部URL,但仅适用于特定的错误代码。 (在这种情况下为404)
I need to be able to use awk to analyze the top URL, but only for a specific error code. (In this case 404)
简化的日志结构如下:
'Request Method, URI, Error Code'
GET, /foo, 404
GET, /foo, 200
GET, /foo, 404
GET, /foo, 404
GET, /bar, 200
GET, /bar, 404
GET, /foobar, 404
GET, /foobar, 404
我想要的输出将是(列出具有404错误代码的顶部URL):
My desired output would be (Listing top URLS that have 404 error Code):
3 /foo
2 /foobar
1 /bar
推荐答案
带有 awk
和 sort
:
awk '$3==404{a[$2]++}END{for(url in a){print a[url], url}}' log.txt | sort -rn
这篇关于awk-根据错误代码查找顶部网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文