AWK从URL删除查询参数



我有一个>1m行的access.log文件。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)" "-"

我需要解析日志行数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没有参数,以获得明确的请求顶部。

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

当您提取字段以对唯一值进行排序和计数时,也需要这样做。

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

最新更新