#!/usr/bin/env perl
use strict;
use warnings;
use diagnostics;
my @blocklines;
my $inblock = 0;
open(my $IFH, '<', 'blockextract.txt') or die($!);
while((my $line = <$IFH>)) {
chomp $line;
if($line =~ /parameters\ after\ change/) {
# Start of a block we want to read
$inblock = 1;
next;
}
# Skip handling line unless we are in a block
next unless($inblock);
if($line =~ /NRG\ location/) {
# Block ends here
# Do whatever you want to do to the block lines
# stored in @blocklines.
# I'm just dumping them to STDOUT
print "*** START ***\n";
print join("\n", @blocklines), "\n";
print "*** END ***\n\n";
# Clean up block
@blocklines = ();
$inblock = 0;
next;
}
# just some line within the interesting block
# remember it for later in @blocklines
push @blocklines, $line;
next;
}
close $IFH;
exit(0);
####
while((my $line = <>)) {
##
##
cat blockextract.txt | perl blockextract.pl