perl to remove lines from file

前端 未结 4 1161
春和景丽
春和景丽 2021-01-29 12:22

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         


        
4条回答
  •  我在风中等你
    2021-01-29 12:56

    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
    

提交回复
热议问题