summaryrefslogtreecommitdiff
path: root/rollingavg
diff options
context:
space:
mode:
Diffstat (limited to 'rollingavg')
-rwxr-xr-xrollingavg21
1 files changed, 21 insertions, 0 deletions
diff --git a/rollingavg b/rollingavg
new file mode 100755
index 0000000..c825fc0
--- /dev/null
+++ b/rollingavg
@@ -0,0 +1,21 @@
+#!/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