Skip to content

Instantly share code, notes, and snippets.

@hyphaltip
Last active February 22, 2019 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyphaltip/505418e620b11ff832a27193cf2e4955 to your computer and use it in GitHub Desktop.
Save hyphaltip/505418e620b11ff832a27193cf2e4955 to your computer and use it in GitHub Desktop.
GriffinEvo_question
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
#!/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