Skip to content

Instantly share code, notes, and snippets.

@phonyphonecall
Last active August 29, 2015 14:15
Show Gist options
  • Save phonyphonecall/cdbe75255d863ffe0c25 to your computer and use it in GitHub Desktop.
Save phonyphonecall/cdbe75255d863ffe0c25 to your computer and use it in GitHub Desktop.
ece556 hw1 part A log parsing
#!/usr/bin/perl
use strict;
use warnings;
#get file in
open(my $fd, "<", $ARGV[0]) or die "cannot open file $!";
#iterate over each line to find max
my $max = -1;
my $count = -1;
while(<$fd>) {
$count++;
next if $count == 0;
my @line = split("\t", $_);
if ($max < $line[1]) {
$max = $line[1];
}
}
print "max temp: $max\n";
seek($fd, 0, 0);
my @binct = (0, 0, 0, 0, 0);
$count = -1;
#iterate over each line to count bins (and total)
while(<$fd>) {
$count++;
next if $count == 0;
my @line = split("\t", $_);
no warnings 'numeric';
my $temp = $line[1] * 1.0000000;
if($temp > 0.1 * $max and $temp <= $max) {
$binct[0]++;
} elsif($temp > 0.01 * $max and $temp <= 0.1 * $max) {
$binct[1]++;
} elsif($temp > 0.001 * $max and $temp <= 0.01 * $max) {
$binct[2]++;
} elsif($temp > 0.0001 * $max and $temp <= 0.001 * $max) {
$binct[3]++;
} elsif($temp <= 0.0001 * $max) {
$binct[4]++;
} else {
warn "bad temp: $temp\n";
}
}
close($fd);
#convert to percentage
$binct[0] = ($binct[0] / $count) * 100;
$binct[1] = ($binct[1] / $count) * 100;
$binct[2] = ($binct[2] / $count) * 100;
$binct[3] = ($binct[3] / $count) * 100;
$binct[4] = ($binct[4] / $count) * 100;
print "bin0: $binct[0]%\n";
print "bin1: $binct[1]%\n";
print "bin2: $binct[2]%\n";
print "bin3: $binct[3]%\n";
print "bin4: $binct[4]%\n";
print "done\n";
@phonyphonecall
Copy link
Author

Usage

  • chmod 755 {script_name}
  • ./{script_name} {path_to_sa_log}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment