user3389597
user3389597

Reputation: 471

Mathematical operation on columns of two files

I have a file with 2 columns. I would like to do the following operation: Col1/ [ (1+0.214/(Col2*Col2))^2 ]. To do that I write an awk command:

awk '{print $1/(1+.214/($2*$2))*(1+.214/($2*$2))}' ab.txt > G1.txt

But I am getting the same numbers as column1 in the output. Could anyone please tell me where I am going wrong?

Thank you.

Upvotes: 0

Views: 374

Answers (1)

F. Knorr
F. Knorr

Reputation: 3055

It is no surprise that you get the same numbers again because there is one pair of parentheses missing. Look carefully at your expression! What you calculate is (y/x) * x (y divided by x multiplied by x). What you need is y/(x*x) or in other words

awk '{print $1/((1+.214/($2*$2))*(1+.214/($2*$2)))}' ab.txt > G1.txt

Don't worry! If i had gotten a penny for every missing parenthesis, ...

Upvotes: 1

Related Questions