zoukankan      html  css  js  c++  java
  • shell编程题(三十三)

    题目:

      获得访问前10位的ip地址

    答案:  

    awk '{print $1}' access.log | sort | uniq -c | sort

    access.log

    172.16.8.11 - - [19/Sep/2018:12:35:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613
    172.16.8.1 - - [19/Sep/2018:12:43:08 +0800] "GET /images/loading.gif HTTP/1.1" 200 404
    172.16.8.1 - - [19/Sep/2018:12:43:08 +0800] "POST /init HTTP/1.1" 200 207
    172.16.8.1 - - [19/Sep/2018:12:43:12 +0800] "POST /init HTTP/1.1" 200 207
    172.16.8.1 - - [19/Sep/2018:12:43:16 +0800] "GET / HTTP/1.1" 200 7612
    172.16.8.1 - - [19/Sep/2018:12:43:16 +0800] "GET /css/default-init.css?1537325099834 HTTP/1.1" 304 -
    172.16.8.1 - - [19/Sep/2018:12:43:16 +0800] "GET /js/lib/jquery/jquery.min.js HTTP/1.1" 304 -
    172.16.8.1 - - [19/Sep/2018:12:43:16 +0800] "GET /images/logo.png HTTP/1.1" 304 -
    172.16.8.11 - - [19/Sep/2018:12:45:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:12:55:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:13:05:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:13:15:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613
    172.16.8.11 - - [19/Sep/2018:13:25:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613
    172.16.8.11 - - [19/Sep/2018:13:35:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613
    172.16.8.11 - - [19/Sep/2018:13:45:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613
    172.16.8.11 - - [19/Sep/2018:13:55:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:14:05:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:14:15:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:14:25:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:14:35:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:14:45:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613

    uniq 命令只能合并相邻相同选项的行,所以前面需要用一个sort排序把相同或者相似的项排在一起。

  • 相关阅读:
    linux下拼接字符串的代码
    postgresql实现插入数据返回当前的主键ID
    记录一个linux下批处理的代码
    iptables
    mybatis获得执行insert的返回值
    git commit之后撤销
    仿照CIFAR-10数据集格式,制作自己的数据集
    C/C++ 在处理文件所在路径下创建子目录
    C/C++ 图像二进制存储与读取
    C/C++ 文件路径解析
  • 原文地址:https://www.cnblogs.com/wanghao-boke/p/12286871.html
Copyright © 2011-2022 走看看