-
Notifications
You must be signed in to change notification settings - Fork 0
/
split-log.pl
executable file
·51 lines (46 loc) · 1.05 KB
/
split-log.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
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
use strict;
use warnings;
my %handles;
my $stack;
my $buffer;
my $channel;
my $newStack;
my $newChannel;
$_ = <>;
if (m/^[0-9:]+ \[[^@]+@[a-z]+_([a-z0-9-]+?)-[0-9] [^]]+\]\[([A-Z]+)\] /) {
$stack = $1;
$channel = $2;
open( $handles{$stack}, '>', $stack );
s/^[0-9:]+ \[[^@]+@[a-z]+_([a-z0-9-]+?)-[0-9] [^]]+\]\[([A-Z]+)\] //;
$buffer = $_;
}
while (<>) {
if (m/^[0-9:]+ \[[^@]+@[a-z]+_([a-z0-9-]+?)-[0-9] [^]]+\]\[([A-Z]+)\] /) {
$newStack = $1;
$newChannel = $2;
if ( !$handles{$newStack} ) {
open( $handles{$newStack}, '>', $newStack );
}
s/^[0-9:]+ \[[^@]+@[a-z]+_([a-z0-9-]+?)-[0-9] [^]]+\]\[([A-Z]+)\] //;
if ($newStack eq $stack && $newChannel eq $channel) {
chomp $buffer;
chomp $buffer;
$buffer .= $_;
} else {
if ($buffer =~ m/\S/ms) {
$buffer =~ s/^/$channel /mg;
print { $handles{$stack} } $buffer ;
}
$channel = $newChannel;
$buffer = $_;
}
$stack = $newStack;
} else {
$buffer .= $_;
}
}
if ($buffer =~ m/\S/ms) {
$buffer =~ s/^/$channel /mg;
print { $handles{$stack} } $buffer;
}