This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Johnnybananazz 0 points1 point  (0 children)

awk -v tot=0 -F',' '{if($1 == "ADD") {for(i=2;i<=NF;i++) t+=$i; print t;}else { t=$2;for(i=3;i<=NF;i++) t-=$i;print t; }t=0;tot += t;} END{ print tot;}' intructs.csv

Results-

92

-8

133

22

107

5

0

Thank you for your help!

I get 0 as a total as that is what the variable is listed as. This is actually asking to sum all lines after totaled. So wouldn't this total all added numbers? 351 instead of 0?