-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmetersCSVExtractor.pl
More file actions
executable file
·93 lines (66 loc) · 2.07 KB
/
Copy pathmetersCSVExtractor.pl
File metadata and controls
executable file
·93 lines (66 loc) · 2.07 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/perl
open (OUTFILE, ">Meters.csv");
print OUTFILE "Timestamp";
print "------------------------------------------------------------\n";
my @SEARCHSTR = @ARGV;
print "Search strings are: \n";
foreach my $a (@SEARCHSTR) {
print "$a\n";
print OUTFILE",";
print OUTFILE "$a";
}
print OUTFILE "\n";
@files = <meters-output*.txt>;
$timestampformat = "^.*?(..:..:...*?) .*-.*";
foreach $file (@files) {
print "parsing" . $file . "\n";
$linesparsed = 0 ;
$blocksparsed = 0;
open (MYFILE, $file);
$lastts="";
$inblock=0;
$block="";
while (<MYFILE>) {
$linesparsed++;
#check for the timestamp to see if start of block and save it
if(/$timestampformat/){
#if you are in meter block and hit another timestamp you are done with that section
if($inblock == 1){
$blocksparsed++;
my $csvline=parse_block($block,\@SEARCHSTR);
print OUTFILE $lastts . $csvline . "\n";
print $lastts . $csvline . "\n";
$block="";
$inblock=0;
}
$lastts=$1;
}
#next we check for the [meters] tag to confirm that file was read and start saving block
elsif(/\[meters\]/){
$block=$lastts . "\n";
$inblock=1;
}else{
#if you are still in block just keep appending lings to block for processing
if ($inblock == 1){
$block=$block . $_ ;
}
}
}
print "\n$linesparsed lines parsed, $blocksparsed blocks parsed\n";
close (MYFILE);
}
close (OUTFILE);
################# SUBS #################
sub parse_block{
my ($block) = @_[0];
my @SEARCHSTR = @{$_[1]};
my $retstr="";
#print $block . "\n";
foreach $searchstr (@SEARCHSTR) {
if( $block=~ /\n.*$searchstr.*? = (\d*)/ ) {
#print "found $searchstr = $1\n";
$retstr=$retstr . "," . $1;
}
}
return $retstr
}