Q:

Math operations bewteen columns with AWK

I have a data file like this:
a 1 1  m n l o p
b 2 2
c 3 3

I want to do math calculations by using columns m n l o and p in order to get the following output:
a 1*m+1*n+p+o-l
b 2*m+2*n+p+o-l
c 3*m+3*n+p+o-l

Do you have any idea how to do this in AWK?

A:

Ugly but it seems to work: 
awk 'NR==1{ m = $4; n = $5; l= $6; o = $7; p= $8}{ print $1,$2*m+$3*n+p+o-l }' yourfile

The first part is catching your m n l o p and storing them in variables and the second parts executes your desired math operation for every line. 

