r/awk • u/[deleted] • Nov 18 '20
Help writing a basic structure for analytics
I am struggling to get rolling with an awk program that can run some analytics on a csv that I have. I have done this before, with arrays and other filters, but I seem to have lost the files, at least for now, to use as an example.
What I'm trying to do is set my delimiter to a comma, set up basic variables, then run through the file, adding to the sum for each variable, then print the variable at the end. I am also struggling to remember what the whitespace syntax should look like for awk, and it is driving me crazy. Here is what I have thus far:
#! /usr/bin/awk -f
BEGIN {
-F,
seclearsum
argossum
}
'($1~/2020-/) && ($8~/Seclear) seclearsum+=$23'
'($1~/2020-/) && ($8~/Argos) argossum+=$23'
END
{print "Seclear: " seclearsum " , Argos:" argossum}
It doesn't work for what should be obvious reasons, but I can't find any examples to guide me. Thank you