gpt4 book ai didi

linux - 从 access.log 中获取前 20 个 IP - 按 IP 排序 - 添加用户代理

转载 作者:太空狗 更新时间:2023-10-29 11:12:26 26 4
gpt4 key购买 nike

使用此命令可以从 apache access.log 中获取前 20 个 Ips

cat access_log | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -20

我知道,用户代理可以通过以下方式显示:

awk -F\" '{print $6}'

cut -d\" -f 6

但是如何将它们结合在一起呢?

我想要一个按 IP 排序并在 IP 后面附加用户代理。

例子:

544.45.234.5  Mozilla/5.0   (compatible;    bingbot/2.0;    +http://www.bing.com/bingbot.htm)

最佳答案

使用sed

cat access_log | sed -e 's/^\([[:digit:]\.]*\).*"\(.*\)"$/\1 \2/' | sort -n | uniq -c | sort -nr | head -20

您正在使用 awk '{print $1}' 丢失信息,因此您以后无法获取用户代理。

关于linux - 从 access.log 中获取前 20 个 IP - 按 IP 排序 - 添加用户代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42994633/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com