Adding the corresponding values for every 5th consecutive numbers

Dear All,

I have a file which is as follows:

Input File:

231    100.1
233     99
235     200.9
238     80.1
239     90.2
240     77.0
243     99.5
245     16.20
246     13.55
247     11.8
249     13.7
250     99.6

Expected Output:

231    400
237    247.3
243    141.05
249    113.3

Logic: The 1st column is printing every 5th number in the consecutive order(does not matter if it is not present in the input file). But it starts with the 1st number of the Column 1 and then prints every 5th number.

The second column prints the addition of all the 5 numbers. For example, 232 is not present, therefore we consider 0 corresponding to 232.

I am new in the field and would appreciate tour help.

The logic you describe and the sample you give do not coincide. Anyhow, using 6 as the delta to increase your field 1 counter, try

awk     'NR==1          {printf "%s\t",$1; N=$1+6}
         $1>=N          {printf "%s\n%s\t",sum,N; N+=6; sum=0}
                        {sum+=$2}
         END            {printf "%s\n", sum}
        ' file
231    400
237    247.3
243    141.05
249    113.3
1 Like