forked from anydot/papalala
/
filter_logs.pl
executable file
·41 lines (34 loc) · 982 Bytes
/
filter_logs.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl
use strict;
use warnings;
use Megahal;
my $logpath = $ENV{'HOME'}.'/irclogs/IRCnet';
my @channels = glob "$logpath/#programatori* $logpath/#linux.cz*";
my $maxlines = shift or 40000;
my @bots = qw(Etingo dev_null Papalala Muaddib); # bots and trolls to ignore, case-insensitive
while (my $channel = shift @channels) {
open my $input, $channel
or die "Can't open log";
my $counter = $maxlines;
while (<$input>) {
next
if(/^---/); ## Zmeny data
s/^\d{8} \d\d:\d\d:\d\d//; ## Ustrihnout datum
next
unless (/^</); ## Pokud nikdo nemluvi
s/^<.([^>]*)>\s*(\S+[:,>]+)?\s*//; ## Odstrani nicky, az na samotnou hranici textu
next
if grep( lc($1) eq lc($_) , @bots); # strip bots etc
# + pripadne dalsi komupisu:
next
if (/^\s*$/); ## prazdny radek
last
unless $counter--;
print;
if ($counter % 1000 == 0) {
printf STDERR "%i files and %i lines (cur. file) to go\n",
scalar @channels, $counter;
}
}
close $channel;
}