Chinaunix首页 | 论坛 | 博客
  • 博客访问: 531700
  • 博文数量: 126
  • 博客积分: 851
  • 博客等级: 准尉
  • 技术积分: 1287
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-06 11:21
个人简介

个人最新博客地址http://www.skylway.com/

文章分类

全部博文(126)

文章存档

2016年(2)

2014年(60)

2013年(35)

2012年(29)

分类: Python/Ruby

2012-11-26 15:57:54

分割日志并排序关键字


#!/usr/bin/perl -w
use strict;

my $path="/home/zengkaibin/myperl/filter.log";
my $result1="/home/zengkaibin/logs/sq.log";
my $result2="/home/zengkaibin/logs/usr.log";
my %hashusr;
my %hashsq;
open(FS,"$path")||die "ERROR:cann't open $path:$!";

while(){
       if(/\A.*(86\d\d\d\d\d\d\d\d\d\d\d).*HIT_B:(.*)MSG.*\Z/){
              chomp;
              my $usr=$1;
             my $sq=$2;
            $hashusr{$usr}++;
            $hashsq{$sq}++;
    }
}

open (OUT,">>$result1")||die "ERROR:cann't open $result1:$!";

foreach(sort {$hashsq{$b} <=> $hashsq{$a}} keys %hashsq){
             my $ges1=sprintf("%10d",$hashsq{$_});
             print OUT "$ges1|    $_   \n";
}

open (OUTT,">>$result2")||die "ERROR:cann't open $result2:$!";

foreach(sort {$hashusr{$b} <=> $hashusr{$a}} keys %hashusr){
            my $ges2=sprintf("%10d",$hashusr{$_});
            print OUTT "$ges2|    $_   \n";
}
close(FS);
close(OUT);
close(OUTT);
阅读(1215) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~