Last active
January 3, 2020 15:08
-
-
Save cacology/2bbe9c3481587ea6cf2854e883cba1ed to your computer and use it in GitHub Desktop.
Apple Card accounts to ledger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| CUR_LEDGER=PUTYOURLEDGERFILEHEREFORAUTOMATICMATCHING! | |
| FIELDS="date,payee,note,amount" | |
| # convert to text: delicate based on how the PDF renders | |
| pdftotext -layout "$1" - > "$1.txt" | |
| # extract lines with transactions, / \d\d/ | |
| grep '^\d\d/\d\d.*\d\d$' "$1.txt" > "$1.transactions.txt" | |
| # cull all commas: ledger thinks they always make new fields | |
| sed -E 's_,_;_' "$1.transactions.txt" > "$1.transactions.culled.txt" | |
| # convert those lines to CSV | |
| sed -E 's_([0-9/]+)[[:space:]]{2,}([[:alpha:][:space:]\*\./]*)[[:space:]](.*)[[:space:]]{2,}(.*)_"\1", "\2", "\3", \4_' "$1.transactions.culled.txt" > "$1.csv" | |
| echo "$FIELDS" | cat - "$1.csv" > "$1.csv.tmp.csv" | |
| ledger convert "$1.csv.tmp.csv" --input-date-format "%m/%d/%Y" -f "$CUR_LEDGER" --account "Liabilities:Apple Mastercard" --auto-match --rich-data > "$2" | |
| rm "$1.csv" "$1.csv.tmp.csv" "$1.txt" "$1.transactions.txt" "$1.transactions.culled.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment