awk从URL中删除查询参数
我有访问文件,带有> 1m行。行的外观:
113.10.154.38 - - [27/May/2016:03:36:26 +0200] "POST /index.php?option=com_jce&task=plugin&plugin=imgmanager&file=imgmanager&method=form&cid=20&6bc427c8a7981f4fe1f5ac65c1246b5f=cf6dd3cf1923c950586d0dd595c8e20b HTTP/1.1" 200 22 "-" "BOT/0.1 (BOT for JCE)" "-"
我需要解析日志线以计数10个最常见的URL,但是我需要从URL中删除查询参数。没有查询参数,我写了此代码
awk '{print $7}' test.log | sort | uniq -c | sort -rn | \
head | awk '{print NR,"\b. URL:", $2,"\n Requests:", $1}'
,但是我不知道如何删除查询参数并计数前10个最常见的URL,而无需参数以获得清晰的请求顶部。
I have access.log file with >1m lines. The exaple of line:
113.10.154.38 - - [27/May/2016:03:36:26 +0200] "POST /index.php?option=com_jce&task=plugin&plugin=imgmanager&file=imgmanager&method=form&cid=20&6bc427c8a7981f4fe1f5ac65c1246b5f=cf6dd3cf1923c950586d0dd595c8e20b HTTP/1.1" 200 22 "-" "BOT/0.1 (BOT for JCE)" "-"
I need to parse log lines to count 10 most common urls, BUT i need to remove query params from url. Without query params i wrote this code
awk '{print $7}' test.log | sort | uniq -c | sort -rn | \
head | awk '{print NR,"\b. URL:", $2,"\n Requests:", $1}'
But i don't know how to remove query params and count top 10 most common urls without params to get clear top of requests.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
sub()
函数从字符串中删除模式。当您提取字段以排序并计算唯一值时,您还需要执行此操作。
Use the
sub()
function to remove a pattern from a string.You also need to do this when you're extracting the field to sort and count unique values.