in reply to Print a previous to previous of a matching line
Hi,
in this case I would take the following approach:
#!/usr/bin/env perl use strict; use warnings; use 5.010; # read first line assuming it is a kind of block seperator my $bsep = <>; $/ = $bsep; while(defined(my $block = <>)) { chomp $block; my @records = split /\n/, $block; next if @records < 3; # malformed block foreach my $record (@records) { say $record; } say "========================"; }
Now you can find and operate on every block how you like.
Best regards
McA
|
|---|