How to continue numbering after a regular expression has been found

Hello, I have a file starting with:

fixedStep chrom=chrX start=1 step=1
0.930
0.955
0.972
0.985
0.993
0.995
0.994
0.990
0.984
0.971
0.942
0.944
0.971
fixedStep chrom=chrX start=200 step=1
0.987

The problem is that, apart from the numbers shown, there are these headers found in the file multiple times. I want to construct a program that stores the position and the value, that means:

1 0.930
2 0.955

etc 

whenever you find a line, the numbering continues from the next line, that means:

201 0.987

I have constructed the following code:

#!/usr/bin/perl -w

print "Please enter the filename of your file: ";
$dnafilename = <STDIN>;
chomp $dnafilename;

unless ( -e $dnafilename) {

    print "File \"$dnafilename\" doesn't seem to exist!!\n";
    exit;
}

unless ( open(DNAFILE, $dnafilename) ) {

    print "Cannot open file \"$dnafilename\"\n\n";
    exit;
}
while ( <DNAFILE> ) {
            
            unless   (/fixedStep chrom=chrX start=(.+) step=1/) {
            $counter = $1;

        for ($counter = 1; $counter < $. ; $counter++) {
           
            }
             print "$counter\t$0\n";
             
            }
}

close DNAFILE;


exit;

Any help would be greatly appreciated!!!

---------- Post updated at 11:33 AM ---------- Previous update was at 11:29 AM ----------

I am sorry...the numbering starts from where it is indicated by the number stored in the field start, that is start = 200 etc...So this means:

200 0.987
etc

nawk -F'[ =]' 'NF>1{start=$5;next}{print start++,$0}' myFile
1 Like

Thank you very much mate :slight_smile:

Since I am a newbie in programming, I would like to implement this in Perl...Does anybody have any idea how I could do that, or include this awk command in my Perl code???