From 80fd0f8fe145e9c52e3b4a94a2fa2f7b071c4796 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 7 Jan 2022 11:04:53 +0000 Subject: script now cleans itself up a bit better --- process_hsbc_transactions.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'process_hsbc_transactions.sh') diff --git a/process_hsbc_transactions.sh b/process_hsbc_transactions.sh index 5ab0caf..fc9afb6 100755 --- a/process_hsbc_transactions.sh +++ b/process_hsbc_transactions.sh @@ -4,7 +4,11 @@ tf="TransactionHistory.csv" trap 'rm -f "$tmpfile"' EXIT tmpfile=$(mktemp) || exit 1 -echo "Our tempfile is $tmpfile" +echo "Our main tempfile is $tmpfile" + +trap 'rm -f "$ledgertmp"' EXIT +ledgertmp=$(mktemp) || exit +echo "Our ledger formatted tempfile is $ledgertmp" if [[ -a "~/Downloads/$tf" ]]; then tpath="~/Downloads/$tf" elif [[ -a "$(pwd)/$tf" ]]; then tpath="$(pwd)/$tf" @@ -21,10 +25,17 @@ echo -e "Transaction File: $tpath" sed -i $'1s/^\uFEFF//' $tpath while read line; do + line=${line/"-"/"£"} echo -e "$line\n$(cat $tmpfile)" > $tmpfile done < $tpath +# how to append to a text file in bash echo -e "Date,Description,Amount\n$(cat $tmpfile)" > $tmpfile + echo "Sorted transaction file: $tmpfile" -$(ledger convert --input-date-format "%d/%m/%Y" $tmpfile > toss) +$(ledger convert --input-date-format "%d/%m/%Y" $tmpfile > $ledgertmp) + +# Remove the erroneous Equity lines +sed -i '/Equity:Unknown/d' $ledgertmp +cat $ledgertmp -- cgit v1.2.3