in reply to Compute previous lines data

If I understand your description of the task, it looks like your two snippets of sample data are different in ways that they shouldn't be -- that's a bit confusing.

But based on your description (and assuming that the input data is correctly sorted according to the values of the "reference_position_begin" and "reference_position_end" columns), I think the following would do what you want:

#!/usr/local/bin/perl use strict; use warnings; my $prev_key = ''; my $match_count; while (<>) { my @flds = split; my $key = join ' ', @flds[6,7]; $match_count = 0 if ( $key ne $prev_key ); $prev_key = $key; splice( @flds, 6, 0, ++$match_count ); print join( "\t", @flds ), "\n"; }
If the input data isn't sorted properly yet, just look up the unix "sort" command to take care of that.