Created
June 27, 2014 20:56
-
-
Save mpapec/847669e027df33046fac to your computer and use it in GitHub Desktop.
SO jaypal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl -F, -lane' | |
BEGIN { | |
$x = pop; | |
## Create array of arrays from start and end ranges | |
## $range = ( [0,0] , [1,10] ... ) | |
(undef, @range)= map { chomp; [split /,/] } <>; | |
@ARGV = $x; | |
} | |
## Skip the first line | |
next if $. ==1; | |
## Create hash of hash | |
## $line = '[0,0]' => { "count" => counts , "sum4" => sum_of_col4 , "sum5" => sum_of_col5 } | |
for (@range) { | |
if ($F[3] >= $_->[0] && $F[3] <= $_->[1]) { | |
$line{"@$_"}{"count"}++; | |
$line{"@$_"}{"sum4"} +=$F[3]; | |
$line{"@$_"}{"sum5"} +=$F[4]; | |
} | |
} | |
}{ | |
print "StartRange,EndRange,Count,Sum-4,Sum-5"; | |
print join ",", @$_, | |
$line{"@$_"}{"count"} //"NotFound", | |
$line{"@$_"}{"sum4"} //"NotFound", | |
$line{"@$_"}{"sum5"} //"NotFound" | |
for @range | |
' slab input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment