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

  • 相关阅读:
    Extjs 动态改变列名
    ext+dwr DynamicGridPanel 封装 态创建ext grid
    extjs 动态表单模板二
    extjs 动态表单模板
    EXTJS 学习笔记(共17项,20090924更新)
    Ext核心API详解Ext.tree.TreePanel
    ExtJS GridPanel动态加载列
    ExtJs之combobox详解
    在 LotusScript 中为自定义对象模拟事件
    Firefox下如何将回车键转为Tab键
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351019.html
Copyright © 2011-2022 走看看