zoukankan      html  css  js  c++  java
  • perl 正则分组 或

    jrhmpt01:/tmp# cat sum.pl 
    open (LOG ,"<","tmp.out");  
                        while (<LOG>) {  
                        chomp; 
    ##10.171.246.184 - - [05/Feb/2016:20:32:50 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 180.120.21.62
    #10.171.246.184 - - [05/Feb/2016:20:46:24 +0800] "GET /web/noauth?method=%2Fnotice%2Fpage&type=1&pageNum=1&pageSize=5&_=1454676377831 HTTP/1.1" 200 1134 0.032 122.234.182.28
    if ($_ =~ /.*s+"(POST|GET)s*(.*?)s*HTTP.*?(d{1,3}.d{1,3}.d{1,3}.d{1,3})$/){
    print "$1 is $1
    ";
    $url=$2;
    print "$url is $url
    ";
    $ip=$3;
    print "$ip is $ip
    ";
    $var=$url.$ip;
    $hash{$var}++;
    }}
    while(my($ip, $times) = each %hash) {
                       print "$ip access count(*) ==   $times
    ";
    };
    jrhmpt01:/tmp# cp tmp.out tmp.out.bak
    jrhmpt01:/tmp# vim tmp.out
    jrhmpt01:/tmp# perl sum.pl 
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is GET
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    $1 is POST
    $url is /web/sendregistersmscode
    $ip is 117.149.104.182
    /web/sendregistersmscode117.149.104.182 access count(*) ==   10
    jrhmpt01:/tmp# cat tmp.out
    10.252.142.174 - - [06/Feb/2016:08:05:13 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.000 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:13 +0800] "GET /web/sendregistersmscode HTTP/1.1" 200 49 0.000 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:19 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:23 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:24 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:29 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:34 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:35 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:37 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.002 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:51 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    jrhmpt01:/tmp# grep 117.149.104.182  tmp.out
    10.252.142.174 - - [06/Feb/2016:08:05:13 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.000 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:13 +0800] "GET /web/sendregistersmscode HTTP/1.1" 200 49 0.000 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:19 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:23 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:24 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:29 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.252.142.174 - - [06/Feb/2016:08:05:34 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:35 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:37 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.002 117.149.104.182
    10.171.246.184 - - [06/Feb/2016:08:05:51 +0800] "POST /web/sendregistersmscode HTTP/1.1" 200 49 0.001 117.149.104.182

  • 相关阅读:
    hdu 2604 Queuing(矩阵快速幂乘法)
    hdu 5591 ZYB's Game
    hdu 5590 ZYB's Biology
    CodeForces
    uva 193 Graph Coloring(图染色 dfs回溯)
    uva 10004 Bicoloring(dfs二分染色,和hdu 4751代码差不多)
    CSU
    hdu 5115 Dire Wolf(区间dp)
    腾讯装扮下拉选项卡特效(QQ空间)
    楼梯式定位导航系统
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351019.html
Copyright © 2011-2022 走看看