sort correctly by date number, ignore some lines klin
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 23 Sep 2016 17:24:34 +0000 (19:24 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 23 Sep 2016 17:24:34 +0000 (19:24 +0200)
klin/from-by-time.pl

index 332362a..0342043 100755 (executable)
@@ -11,6 +11,7 @@ while(<>) {
        my ( $mon, $dd, $time, $host, $daemon, $msg ) = split(/\s+/,$_,6);
 
        next unless $msg =~ m/from=<([^>]+)>/;
+       next if $msg =~ m/(NOQUEUE|FILTER)/;
        my $from = $1;
 
        my $t = $time;
@@ -25,17 +26,18 @@ while(<>) {
 #warn "# stat = ", dump( $stat );
 
 foreach my $mon ( sort keys %$stat ) {
-       foreach my $dd ( sort keys %{$stat->{$mon}} ) {
+       foreach my $dd ( sort { $a <=> $b } keys %{$stat->{$mon}} ) {
                foreach my $t ( sort keys %{ $stat->{$mon}->{$dd} } ) {
                        my $n = 0;
                        my $e = $stat->{$mon}->{$dd}->{$t};
+                       my $fmt = "%3s %2s %5s %4d %s\n";
                        foreach my $email ( sort { $e->{$b} <=> $e->{$a} } keys %$e ) {
                                if ( $n == 0 ) {
-                                       printf "%3s %2s %5s %d %s\n", $mon, $dd, $t, $e->{$email}, $email;
+                                       printf $fmt, $mon, $dd, $t, $e->{$email}, $email;
                                } elsif ( $n == 5 ) { # XXX top
                                        last;
                                } else {
-                                       printf "%3s %2s %5s %d %s\n", '', '', '', $e->{$email}, $email;
+                                       printf $fmt, '', '', '', $e->{$email}, $email;
                                }
                                $stat->{_from}->{$email} += $e->{$email};
                                $n++;
@@ -44,6 +46,7 @@ foreach my $mon ( sort keys %$stat ) {
        }
 }
 #print "_from = ",dump( $stat->{_from} );
+print "# XXX count,email\n";
 foreach my $email ( sort { $stat->{_from}->{$b} <=> $stat->{_from}->{$a} } keys %{ $stat->{_from} } ) {
        printf "%4d %s\n", $stat->{_from}->{$email}, $email;
 }