From 0a354ef141694383ad4339be36451c28149162fd Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 7 Jan 2022 12:20:14 +0000 Subject: removed all the echo commands which don't work when redirecting --- process_hsbc_transactions.sh | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/process_hsbc_transactions.sh b/process_hsbc_transactions.sh index fc9afb6..0b37204 100755 --- a/process_hsbc_transactions.sh +++ b/process_hsbc_transactions.sh @@ -2,40 +2,36 @@ tf="TransactionHistory.csv" +# Automatic cleanup trap 'rm -f "$tmpfile"' EXIT tmpfile=$(mktemp) || exit 1 -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" +# Check for presence of transaction file +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." +else "Cannot find $tf. Expecting it either in ~/Downloads or in current folder."; exit 1 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 +# read the file and process lines while read line; do - line=${line/"-"/"£"} + 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" - +# use ledger to convert to ledger format $(ledger convert --input-date-format "%d/%m/%Y" $tmpfile > $ledgertmp) # Remove the erroneous Equity lines sed -i '/Equity:Unknown/d' $ledgertmp + +# dump to sdout for further redirection cat $ledgertmp -- cgit v1.2.3