I have file that looks like:
ATOM 2517 O VAL 160 8.337 12.679 -2.487
ATOM 2518 OXT VAL 160 7.646 12.461 -0.386
TER
ATOM 2519 N VAL 161 -14.431 5.789 -2
So, for each set of 6 consecutive lines, you want to discard all but the third line if the second line is a TER?
TIMTOWTDI, but this should work:
my @queue;
while (<>) {
push @queue, $_;
@queue = $queue[2] if @queue == 6 and $queue[1] =~ /^TER$/;
print shift @queue if @queue == 6;
}
print @queue; # assume no TERs in last 4 lines