Sum product of even/odd lines

Hi,
I have a text file like this

    6.0000E-02   0.00000E+00 0.0000   0.00000E+00 0.0000
    7.0000E-02   5.00000E-10 1.0000   5.00000E-10 1.0000
    8.0000E-02   3.00000E-09 0.4082   3.00000E-09 0.4082
    9.0000E-02   3.50000E-09 0.3780   3.50000E-09 0.3780
    1.0000E-01   1.00000E-09 0.7071   1.00000E-09 0.7071

having 2*n+1 columns and m rows

I would like to obtain a file with one column containing in each row the following formula for that row:

col(2)*col(3)+col(4)*col(5)+col(6)*col(7)+...

Is there a way to do this with awk?

Many thanks

If you are so sure about what you said, below is the code

awk '{out = 0; for(i = 2; i <= NF; i++) {if(i % 2 == 0) {p = $i} else {out = out + (p * $i)}}; print out}' file
1 Like

A bit shorter

awk '{out = 0; for(i = 3; i <= NF; i+=2) {out += $(i-1) * $i }; print out}' file
1 Like