Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
exec > >(column -t)
file="${1:-data.bean}"
from="${2:-1000-01-01}"
to="${3:-9999-12-31}"
aex='account ~ "Expenses"'
alo='account ~ "Liabilities:Loans"'
ain='account ~ "Income"'
data=`bean-query $file 'SELECT year, month, root(account, 1) as ar, sum(position) FROM date > '$from' AND date < '$to' WHERE ('$aex' OR '$alo' OR '$ain') GROUP BY year, month, ar ORDER BY year, month, ar FLATTEN'`
echo "$data" | gawk 'NR>2 {a[$1][$2][$5][$3]=a[$1][$2][$5][$3]?a[$1][$2][$5][$3]$4:$4} END{
printf "YYYY/MM Expenses Loans Income Balance\n"
for (i in a)
for (j in a[i])
for (k in a[i][j])
printf "%d/%02d %s %s %s %s %s\n", i, j,
a[i][j][k]["Expenses"]+0,
a[i][j][k]["Liabilities"]+0,
-(a[i][j][k]["Income"]+0),
-(a[i][j][k]["Expenses"]+a[i][j][k]["Liabilities"]+a[i][j][k]["Income"]+0),
k
}'
YYYY/MM Expenses Loans Income Balance
2013/01 3600 0 17500 13900 IRAUSD
2013/01 9490.53 -439.58 15119.1 6068.15 USD
2013/01 0 0 15 15 VACHR
2013/02 2400 0 0 -2400 IRAUSD
2013/02 7309.81 66.58 10479.4 3103.01 USD
2013/02 0 0 10 10 VACHR
2013/03 2400 0 0 -2400 IRAUSD
2013/03 7435.73 -17.08 11079.4 3660.75 USD
2013/03 0 0 10 10 VACHR
2013/04 2400 0 0 -2400 IRAUSD
2013/04 7459.09 -92.28 10479.4 3112.59 USD
2013/04 0 0 10 10 VACHR
2013/05 2400 0 0 -2400 IRAUSD
2013/05 7471.74 -46.16 10479.4 3053.82 USD
2013/05 0 0 10 10 VACHR
2013/06 2400 0 0 -2400 IRAUSD
2013/06 7374.14 33.32 10479.4 3071.94 USD
2013/06 0 0 10 10 VACHR
2013/07 1900 0 0 -1900 IRAUSD
2013/07 7454.35 -18.6 10229.4 2793.65 USD
2013/07 0 0 10 10 VACHR
2013/08 9588.54 66.47 13919.1 4264.09 USD
2013/08 0 0 15 15 VACHR
2013/09 7388.98 34.62 9290.79 1867.19 USD
2013/09 0 0 10 10 VACHR
2013/10 8134.56 -960.08 9199.6 2025.12 USD
2013/10 168 0 10 -158 VACHR
2013/11 7486.07 -264.87 9260.04 2038.84 USD
2013/11 0 0 10 10 VACHR
2013/12 7162.16 -52.86 9341.36 2232.06 USD
2013/12 0 0 10 10 VACHR
2014/01 3600 0 17500 13900 IRAUSD
2014/01 9502.48 47.75 15962.5 6412.3 USD
2014/01 0 0 15 15 VACHR
2014/02 2400 0 0 -2400 IRAUSD
2014/02 7379.46 162.35 10479.4 2937.59 USD
2014/02 0 0 10 10 VACHR
2014/03 2400 0 0 -2400 IRAUSD
2014/03 8549.13 -2247.33 10560.1 4258.27 USD
2014/03 0 0 10 10 VACHR
2014/04 2400 0 0 -2400 IRAUSD
2014/04 7374.24 106.56 10479.4 2998.6 USD
2014/04 0 0 10 10 VACHR
2014/05 2400 0 0 -2400 IRAUSD
2014/05 7427.04 24.07 10479.4 3028.29 USD
2014/05 0 0 10 10 VACHR
2014/06 2400 0 0 -2400 IRAUSD
2014/06 7676.3 -60.05 10560.1 2943.82 USD
2014/06 0 0 10 10 VACHR
2014/07 1900 0 0 -1900 IRAUSD
2014/07 9915.7 -310.53 15074.1 5468.95 USD
2014/07 80 0 15 -65 VACHR
2014/08 7533.49 -263.71 9279.4 2009.62 USD
2014/08 0 0 10 10 VACHR
2014/09 7425.79 37.22 9274.53 1811.52 USD
2014/09 0 0 10 10 VACHR
2014/10 7359.1 62 9553.2 2132.1 USD
2014/10 0 0 10 10 VACHR
2014/11 7416.87 -50.51 9279.4 1913.04 USD
2014/11 0 0 10 10 VACHR
2014/12 7176.78 -49.64 9661.58 2534.44 USD
2014/12 0 0 10 10 VACHR
2015/01 3600 0 18000 14400 IRAUSD
2015/01 9524.2 -13.16 15719.1 6208.06 USD
2015/01 0 0 15 15 VACHR
2015/02 2400 0 0 -2400 IRAUSD
2015/02 7349.08 129.52 10265.6 2786.96 USD
2015/02 0 0 10 10 VACHR
2015/03 2400 0 0 -2400 IRAUSD
2015/03 8507.34 -1902.74 10653.3 4048.73 USD
2015/03 72 0 10 -62 VACHR
2015/04 2400 0 0 -2400 IRAUSD
2015/04 7326.84 1.56 10912.2 3583.79 USD
2015/04 0 0 10 10 VACHR
2015/05 2400 0 0 -2400 IRAUSD
2015/05 7476.03 -52.59 10479.4 3055.96 USD
2015/05 0 0 10 10 VACHR
2015/06 2400 0 0 -2400 IRAUSD
2015/06 7527.27 -148.22 10669.6 3290.58 USD
2015/06 0 0 10 10 VACHR
2015/07 2400 0 0 -2400 IRAUSD
2015/07 9369.59 230.96 15490.4 5889.83 USD
2015/07 0 0 15 15 VACHR
2015/08 7537.3 -126.9 9581.1 2170.7 USD
2015/08 0 0 10 10 VACHR
2015/09 7339.41 118.32 9491.82 2034.09 USD
2015/09 0 0 10 10 VACHR
2015/10 7533.51 -190.3 9279.4 1936.19 USD
2015/10 0 0 10 10 VACHR
2015/11 7271.76 -494.55 9279.4 2502.19 USD
2015/11 0 0 10 10 VACHR
2015/12 2069.71 -19.07 4639.7 2589.06 USD
2015/12 0 0 5 5 VACHR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment