awk从URL中删除查询参数

发布于 2025-01-29 01:02:29 字数 595 浏览 1 评论 0原文

我有访问文件,带有> 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記柔刀 2025-02-05 01:02:29

使用sub()函数从字符串中删除模式。

当您提取字段以排序并计算唯一值时,您还需要执行此操作。

awk '{sub(/\?.*/, "", $7); print $7}' test.log | sort | uniq -c | sort -rn | ...

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.

awk '{sub(/\?.*/, "", $7); print $7}' test.log | sort | uniq -c | sort -rn | ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文