Here is my scenario, I have two columns. I need to add the first columns (the easy part). The second column is a percent that I need to subtract by 100 then multiply against the first column for each line, then sum the output for a total
Here is the input:
942330863 96
942172150 95
942099452 92
I need this as an output:
2826602465 160169797
I tried this code, but it's just doing the percentage work and only doing it for the first line and not summing every line.
awk '
BEGIN {FS=","}
NR == 1{ n1 = $1; x = substr((100-$2)/100,2,3); y = x*$1; next }
{ n1 += $1; y += $y }
END { printf ("%-15d%d\n",n1,y)
}'
Thanks all!! I modified it just a little to multiply by a percentage. I added a printf so the large number would be printed instead of the exponential notation.
awk 'END { printf "%-15d%d\n", s, p } { s += $1; p += (100 - $2) * 0.01 * $1 }'
However, I just through some more numbers at the infile: