aboutsummaryrefslogtreecommitdiffstats
path: root/process_hsbc_transactions.sh
diff options
context:
space:
mode:
authorMatthew Lemon <chaffinach+git@protonmail.ch>2022-01-07 10:40:09 +0000
committerMatthew Lemon <chaffinach+git@protonmail.ch>2022-01-07 10:40:09 +0000
commit003008c0cf6a4eacfcd69623d4d9852c4202a209 (patch)
tree896218967902449be9941ffe5f19b95cffb1962e /process_hsbc_transactions.sh
parent0de1dd4efc60be36b7516342c5644c09095702da (diff)
better budget processing script coming along
Diffstat (limited to 'process_hsbc_transactions.sh')
-rwxr-xr-xprocess_hsbc_transactions.sh30
1 files changed, 30 insertions, 0 deletions
diff --git a/process_hsbc_transactions.sh b/process_hsbc_transactions.sh
new file mode 100755
index 0000000..5ab0caf
--- /dev/null
+++ b/process_hsbc_transactions.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+tf="TransactionHistory.csv"
+
+trap 'rm -f "$tmpfile"' EXIT
+tmpfile=$(mktemp) || exit 1
+echo "Our tempfile is $tmpfile"
+
+if [[ -a "~/Downloads/$tf" ]]; then tpath="~/Downloads/$tf"
+elif [[ -a "$(pwd)/$tf" ]]; then tpath="$(pwd)/$tf"
+else "Cannot find $tf. Expecting it either in ~/Downloads or in current folder."
+fi
+
+echo -e "Transaction File: $tpath"
+
+# create the file if it doesn't exist
+# ! [[ -a $tr_rev ]] && touch $tf_rev
+# echo "" |> $tf_rev
+
+# remove the BOM (https://stackoverflow.com/questions/45240387/how-can-i-remove-the-bom-from-a-utf-8-file)
+sed -i $'1s/^\uFEFF//' $tpath
+
+while read line; do
+ echo -e "$line\n$(cat $tmpfile)" > $tmpfile
+done < $tpath
+
+echo -e "Date,Description,Amount\n$(cat $tmpfile)" > $tmpfile
+echo "Sorted transaction file: $tmpfile"
+
+$(ledger convert --input-date-format "%d/%m/%Y" $tmpfile > toss)