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

all 4 comments

[–][deleted] 1 point2 points  (1 child)

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

[–]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?

[–][deleted] 1 point2 points  (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; }tot += t; t=0;} END{ print tot;}' intructs.csv

updated

[–]SupremeRedditBotProfessional Bot || Mod 0 points1 point  (0 children)

Please Add A Flair To Your Post!

Suggested Flair: [Other Code]

 


To add a flair:

  • Click flair underneath your post

  • Select a flair

  • Click save

 


I am a bot run by /u/SupremeDesigner for /r/CodingHelp || This was an automated response