I have a data2process.tempdata file with data in six columns as follows.
# Angle(deg) D1 D2 D3 D4 D5
0.50 0.00E+00 0.00E+00 1.97E-10 3.94E-09 1.97E-10
1.00 0.00E+00 0.00E+00 1.70E-10 3.41E-09 1.70E-10
1.50 0.00E+00 0.00E+00 1.30E-10 2.59E-09 1.30E-10
2.00 0.00E+00 0.00E+00 9.49E-11 1.90E-09 9.49E-11
2.50 0.00E+00 0.00E+00 6.99E-11 1.40E-09 6.99E-11
3.00 0.00E+00 0.00E+00 5.27E-11 1.05E-09 5.27E-11
3.50 0.00E+00 0.00E+00 4.12E-11 8.23E-10 4.12E-11
4.00 0.00E+00 0.00E+00 3.33E-11 6.66E-10 3.33E-11
4.50 0.00E+00 0.00E+00 2.78E-11 5.56E-10 2.78E-11
5.00 0.00E+00 0.00E+00 2.37E-11 4.74E-10 2.37E-11
I want to multiply sixth column(D5) with 3.6E8 and find the first instance when the product becomes equal or less than 0.05. At that point, I want to save the corresponding value in the first column, print it and exit. In the (edited) data shown above, the first instance when the condition is met at 1.5 deg (1.3e-10*3.6e8=0.0468) but it holds true after that too. So echo $ maxangle should be 1.5, not 5.0 which here is the last entry which also satisfies the condition.
awk version is GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)
I was trying with the following awk commands.
maxangle=$(awk -v maxt=0.05; $6 *=3.6e8 '{if($6<=maxt){maxt=$6; maxa=$1}}END{print maxa ; exit} ' data2process.tempdata)
This gives an error *=3.6e8: command not found
maxangle=$(awk -v maxt=0.05 v6="$arg6"*3.6e8 '{if($v6<maxt){maxt=$1; maxa=$1}}END{print maxa ; exit} ' data2process.tempdata)
gives v6=*3.6e8 syntax error
maxangle=$(awk -v maxt=0.05 '{$6 = $6 * 3.6e8 ; if($6<=maxt){maxt=$1; maxa=$1}} END{print maxa ;}' data2process.tempdata)
echo $maxangle
gives me 5.0.
Thanks a lot for all your help. I am sure I can use all of it.
exit
seems a bit useless inEND
block.