aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <chaffinach+git@protonmail.ch>2022-01-07 12:20:14 +0000
committerMatthew Lemon <chaffinach+git@protonmail.ch>2022-01-07 12:20:14 +0000
commit0a354ef141694383ad4339be36451c28149162fd (patch)
tree62e7c6af143715bbcd7f85cef09c4040ad852c4d
parent5cbaa19341aefefeaaa5b4a9f6cda533a562d024 (diff)
removed all the echo commands which don't work when redirecting
-rwxr-xr-xprocess_hsbc_transactions.sh22
1 files 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