I need help with debugging an error in my awk script.
I have a shell script with variable named U_new_i and want to pass it to awk for use in a summation. The original file have the following content.
cat test.txt
-2445.7132000000
-2444.9349000000
-2444.3295000000
-2443.1814000000
-2442.6894000000
-2445.0234000000
-2444.7423000000
-2443.4350000000
-2444.6649000000
U_new_i = -2443.1814000000
which is the 4th record in test.txt
So I obtained
U_new_i=`head -4 test.txt | tail -1 | awk '{print $1}'`
I now want to sum up a function using U_new_i as a reference point as follow
beta=7.9103744257373072296954995748236
W_new=`tail -8 test.txt | awk -v U_new_i="$U_new_i" '{ W_new += exp(-$beta*(U_new_i - $1))} END { print W_new }'`
echo W_new = $W_new
I keep getting an error shown below, which is an indication of awk having problem with passing U-new_i correctly. Any help would be appreciated.
awk: (FILENAME=- FNR=5) warning: exp: argument -3882.6 is out of range
awk: (FILENAME=- FNR=6) warning: exp: argument -1358.53 is out of range
awk: (FILENAME=- FNR=8) warning: exp: argument 2321.12 is out of range
W_new = inf
---------- Post updated at 11:53 AM ---------- Previous update was at 09:45 AM ----------
I found the bug; beta="$beta" needed to be pass to awk as well. Just a total neglect on my part.
Thanks.
---------- Post updated at 11:55 AM ---------- Previous update was at 11:53 AM ----------
I found the bug, beta also needed to be pass as a variable to awk. Just a total negligence on my part.