Skip to content

Instantly share code, notes, and snippets.

@falsycat
Created October 7, 2021 10:20
Show Gist options
  • Save falsycat/8ed6d97b2172677a57a075ea0021969b to your computer and use it in GitHub Desktop.
Save falsycat/8ed6d97b2172677a57a075ea0021969b to your computer and use it in GitHub Desktop.
#!/usr/bin/awk -f
! /^(#|$)/ {
delete io
for (i = 4; i <= NF; ++i) {
split($i, tok, ":")
target = tok[1]
value = int(tok[2])
io[target] = value
sum[target] += value
}
}
END {
targets_ = "money|wmcard|ALL"
split(targets_, targets, "|")
all=0
for (i in targets) {
all += sum[targets[i]]
}
sum["ALL"] = all
for (i in targets) {
klen = length(targets[i])
vlen = 6 # length(sum[targets[i]])
w[i] = klen < vlen? vlen: klen;
}
for (i in targets) printf " %*s |", w[i], targets[i]
print ""
for (i in targets) printf " %*d |", w[i], sum[targets[i]]
print ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment