#!/usr/bin/env bash # # calculates rolling average for numbers via stdin # # here's an example with hledger: # # hledger bal ^in cur:USD -MA --end=thismonth --output-format=csv \ # | tail -n 1 \ # | cut -d',' -f 2- \ # | tr -d '" USD-' \ # | tr ',' '\n' \ # | rollingavg n=0 total=0 declare -i n while read i do n+=1 total=$(bc -l <<< "$total + $i") printf "%.2f\n" $(bc -l <<< "$total / $n") done