Last active
August 30, 2016 06:08
-
-
Save HokieGeek/87a6b908101037a7a4e7b61518b53bac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.csv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk -f | |
BEGIN { | |
FS="," | |
month[1]="Jan"; month[2]="Feb"; month[3]="Mar"; month[4]="Apr" | |
month[5]="May"; month[6]="Jun"; month[7]="Jul"; month[8]="Aug" | |
month[9]="Sep"; month[10]="Oct"; month[11]="Nov"; month[12]="Dec" | |
} | |
NR < 2 || $1 !~ year { next } | |
{ | |
gsub(/"/, "") #" | |
split($1, a, "/") | |
months[a[1]]+=$4 | |
stores[$2]+=$4 | |
total+=$4 | |
} | |
END { | |
PROCINFO["sorted_in"] = "@val_num_asc" | |
print "- By month -" | |
for (m in months) { | |
printf("%s $%d\n", month[m], months[m]) | |
} | |
print "" | |
print "- By store -" | |
for (s in stores) { | |
printf("%-32s $%d\n", s, stores[s]) | |
} | |
print "" | |
printf(" Yearly total: $%d\n", total) | |
printf("Monthly total: $%d\n", (total/12)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment