AnotherAlan
Technical User
Hi All,
Ive written some code to calculate a mid point based on the data in four fields. I would like to include another logical check to establish if either of two fields are less than 1,000,000, and if so use 1,000,000 as the value.
i.e. if either (or both) of $7 and $10 are less than 1m then use 1m as the value(s).
So, if the value of $7 is 200,000 then substitute the value, in the calculation only, for 1,000,000.
Not entirely sure this can be done in one awk statement but i'm thinking that maybe I can check the values against a max variable.
Something like; max=1000000 if $10<max then lhs=$6*max e.t.c
Although I cant get the syntax correct.
All help appreciated.
Alan
Ive written some code to calculate a mid point based on the data in four fields. I would like to include another logical check to establish if either of two fields are less than 1,000,000, and if so use 1,000,000 as the value.
i.e. if either (or both) of $7 and $10 are less than 1m then use 1m as the value(s).
So, if the value of $7 is 200,000 then substitute the value, in the calculation only, for 1,000,000.
Code:
awk -F, '{lhs=$6*$10;rhs=$7*$9;tot=$7+$10;sum=(lhs+rhs)/tot};{print $2,$6,$7,$9,$10,$(NF-3),$(NF-2),$(NF-1),$NF,sum}' myfile
Not entirely sure this can be done in one awk statement but i'm thinking that maybe I can check the values against a max variable.
Something like; max=1000000 if $10<max then lhs=$6*max e.t.c
Although I cant get the syntax correct.
All help appreciated.
Alan