KBC exports bank statements in an awkward format. For instance, there's no structured field for the correspondent's bank account number — this information is lumped together with the description field. Fortunately, awk can come to your rescue
Here is for instance the code that prints your balance
BEGIN {
FS=";" # this is the field separator
RS="\r" # linefeed is the record separator, they are probably using AS400 still
}
{ if (NF == 0) next # there's usually some garbage at the end of the file
total += gensub(/,/, "", "g",$9) # sum up the total for each record
}
END {
print "TOTAL", gensub(/(.+)(..)/, "\\1,\\2", "g", total) # print the total
}
Want to know how much you spent on gas? Here is the code to do just that:
BEGIN {
FS=";" # this is the field separator
RS="\r" # linefeed is the record separator, they are probably using AS400 still
}
{ if ($7 ~ /PAIEMENT CARBURANT/) $11="GAS" sub(/,/, "", $9)
totals[$11] += gensub(/,/, "", "g",$9)
}
END {
for (n in totals) {
print n, gensub(/(.+)(..)/, "\\1,\\2", "g", totals[n]);
}
Tags: