Last active
February 22, 2019 20:40
-
-
Save hyphaltip/505418e620b11ff832a27193cf2e4955 to your computer and use it in GitHub Desktop.
GriffinEvo_question
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
2 zlm z2m | |
1 2 | |
0 2 residual | |
0.1777 5.08123E-002 | |
5.08123E-002 0.4513 | |
1 2 line | |
0.8389 -6.64123E-002 | |
-6.64123E-002 0.554 |
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
# run like | |
# perl parse.pl data.txt | |
# or | |
# cat data.txt | perl parse.pl | |
my %data; | |
my $state = ''; | |
while(<>) { | |
my @row = split; | |
if ($row[-1] =~ /(residual|line)/ ) { | |
$state = $1; | |
# not empty | |
} elsif ( length $state ) { | |
if ( ! exists $data{$state} ) { | |
# first line of residual or state block | |
$data{$state} = [ $row[0] ]; | |
} else { | |
push @{$data{$state}}, $row[1]; | |
} | |
} | |
} | |
for my $type ( keys %data ) { | |
print join("\t", $type, @{$data{$type}}), "\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment