从 Apache 日志中对 uniq IP 地址进行排序 [英] Sort uniq IP address in from Apache log

查看:23
本文介绍了从 Apache 日志中对 uniq IP 地址进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的 apache 日志中提取 IP 地址,对它们进行计数并对其进行排序.

I'm trying to extract IP addresses from my apache log, count them, and sort them.

无论出于何种原因,排序部分都很糟糕.

And for whatever reason, the sorting part is horrible.

命令如下:

cat access.* | awk '{ print $1 }' | sort | uniq -c | sort -n

输出示例:

  16789 65.X.X.X
  19448 65.X.X.X
   1995 138.X.X.X
   2407 213.X.X.X
   2728 213.X.X.X
   5478 188.X.X.X
   6496 176.X.X.X
  11332 130.X.X.X

我不明白为什么这些值没有真正排序.我还尝试删除行开头的空格 (sed 's/^[\t ]*//g') 并使用 sort -n -t" " -k1,它不会改变任何东西.

I don't understand why these values aren't really sorted. I've also tried to remove blanks at the start of the line (sed 's/^[\t ]*//g') and using sort -n -t" " -k1, which doesn't change anything.

有什么提示吗?

推荐答案

这可能有点晚了,但在第一个排序中使用数字会给你想要的结果,

This may be late, but using the numeric in the first sort will give you the desired result,

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

输出:

 29877 93.xxx.xxx.xxx
  17538 80.xxx.xxx.xxx
   5895 198.xxx.xxx.xxx
   3042 37.xxx.xxx.xxx
   2956 208.xxx.xxx.xxx
   2613 94.xxx.xxx.xxx
   2572 89.xxx.xxx.xxx
   2268 94.xxx.xxx.xxx
   1896 89.xxx.xxx.xxx
   1584 46.xxx.xxx.xxx
   1402 208.xxx.xxx.xxx
   1273 93.xxx.xxx.xxx
   1054 208.xxx.xxx.xxx
    860 162.xxx.xxx.xxx
    830 208.xxx.xxx.xxx
    606 162.xxx.xxx.xxx
    545 94.xxx.xxx.xxx
    480 37.xxx.xxx.xxx
    446 162.xxx.xxx.xxx
    398 162.xxx.xxx.xxx

这篇关于从 Apache 日志中对 uniq IP 地址进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆