- 论坛徽章:
- 7
|
比如文件:
appid: d30b9f
times: 3
type: index, air
areaid: 101240412, 101240508
appid: 71f520
times: 7
type: index, forecast3d, air
areaid: 101110601, 101280601, 101190801, 101200101
appid: aa2f1a
times: 4
type: forecast5d, air
areaid: 101120101, 101290402, 101090101, 101180101
61.4.184.81 2256
61.4.184.93 8147
61.4.184.90 7226
61.4.184.92 7048
perl abc.pl *.txt- #!/usr/bin/perl
- my ( %data, %ip );
- while (<>) {
- if (/^[ait]/) {
- my ( undef, $appid ) = split;
- my ( undef, $times ) = split /\s+/, <>;
- my ( undef, @type ) = <> =~ /(\w+)/g;
- my ( undef, @areaid ) = <> =~ /(\w+)/g;
- $data{$appid}{times} += $times;
- $data{$appid}{type}{$_}++ for @type;
- $data{$appid}{areaid}{$_}++ for @areaid;
- }
- elsif (/^\s*$/) { next }
- elsif (/^\d/) {
- my ( $ip, $count ) = split;
- $ip{$ip} += $count;
- }
- }
- while ( my ( $k, $v ) = each %data ) {
- print "appid:\t$k$/";
- print "times:\t$v->{times}$/";
- print "type:\t", join( ', ', keys %{ $v->{type} } ), $/;
- print "areaid:\t", join( ', ', keys %{ $v->{areaid} } ), $/, $/;
- }
- while ( my ( $k, $v ) = each %ip ) {
- print "$k\t$v$/";
- }
复制代码 |
|