-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogmerge.pl
executable file
·56 lines (52 loc) · 1006 Bytes
/
logmerge.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
52
53
54
55
56
#!/usr/bin/perl
use strict;
use warnings;
use List::Util 'sum';
my @logs = @ARGV;
# open handles
my %handle;
for my $log ( @logs ) {
open my $fh,'<', $log or die $!;
$handle{$log} = $fh;
}
# forward all handles to the /^Iteration\b/ line
for my $handle ( values %handle ) {
SEEK: while ( ! eof($handle) ) {
if ( defined( $_ = <$handle> ) ) {
last SEEK if /^Iteration\b/;
}
}
}
MERGE: while(1) {
my @records;
my $length;
for my $handle ( values %handle ) {
if ( ! eof($handle) ) {
my $line = readline($handle);
chomp($line);
my @fields = split /\t/, $line;
push @records, \@fields;
$length = $#fields;
}
else {
last MERGE;
}
}
my @merge;
for my $i ( 0 .. $length ) {
my @values;
my $istext;
for my $r ( @records ) {
my $val = $r->[$i];
$istext = $val if $val =~ /^'/;
push @values, $val;
}
if ( $istext ) {
push @merge, $values[0];
}
else {
push @merge, ( sum(@values)/scalar(@values) );
}
}
print join( "\t", @merge ), "\n";
}