awk: Columns which are numbers have value 0 when used in arithmetic operations
by Johnny_Metal from LinuxQuestions.org on (#513ZN)
Hello everyone,
I am developing a script which picks up some statistical data from https://corona-stats.online/US and displays it in a certain format.
The first part of the script is:
Code:grep 'Florida' "$HOME"/tmp/corona | sed 's/\s*//g ; s/a//g ; s/a"/;/g'which gives the output:
Code:7;Florida;659;0;13;646;1.97;0.00;96a-^2;583a-^2Now, I want to do some simple arithmetic with awk. I want to divide column 4 by the sum of columns 4 and 5. I've tried piping the above output to:
Code:awk -F';' '{print $4/($4+$5)}'but I get the error Code:awk: cmd. line:1: (FILENAME=- FNR=1) fatal: division by zero attemptedI guess that this has something to do with the fact that other columns in this row are strings, but I don't know how to solve it.
Any suggestions?


I am developing a script which picks up some statistical data from https://corona-stats.online/US and displays it in a certain format.
The first part of the script is:
Code:grep 'Florida' "$HOME"/tmp/corona | sed 's/\s*//g ; s/a//g ; s/a"/;/g'which gives the output:
Code:7;Florida;659;0;13;646;1.97;0.00;96a-^2;583a-^2Now, I want to do some simple arithmetic with awk. I want to divide column 4 by the sum of columns 4 and 5. I've tried piping the above output to:
Code:awk -F';' '{print $4/($4+$5)}'but I get the error Code:awk: cmd. line:1: (FILENAME=- FNR=1) fatal: division by zero attemptedI guess that this has something to do with the fact that other columns in this row are strings, but I don't know how to solve it.
Any suggestions?