aboutsummaryrefslogtreecommitdiffstats
path: root/process_hsbc_transactions.sh
blob: 5ab0caf87f79bb0bf8b98090d7871717faf5308b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)