diff --git a/container/src/hledger-flow/accounts/capital-one/capital-one-shared.bash b/container/src/hledger-flow/accounts/capital-one/capital-one-shared.bash index 0807d04..3393a83 100755 --- a/container/src/hledger-flow/accounts/capital-one/capital-one-shared.bash +++ b/container/src/hledger-flow/accounts/capital-one/capital-one-shared.bash @@ -2,7 +2,7 @@ # docker-finance | modern accounting for the power-user # -# Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC) +# Copyright (C) 2021-2026 Aaron Fiore (Founder, Evergreen Crypto LLC) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -38,7 +38,9 @@ function parse_credit() { lib_preprocess::assert_header "Transaction Date,Posted Date,Card No.,Description,Category,Debit,Credit" - gawk -v global_year="$global_year" -v global_subaccount="$global_subaccount" \ + gawk --csv \ + -v global_year="$global_year" \ + -v global_subaccount="$global_subaccount" \ '{ if (NR<2 || !NF || $1 !~ global_year) next @@ -47,31 +49,35 @@ function parse_credit() printf $2 OFS # Posted Date printf $3 OFS # Card No. + # Description sub(/%/, "%%", $4) - printf $4 OFS # Description + gsub(/"/, "", $4) + printf "\"" $4 "\"" OFS - printf $5 OFS # Category + printf "\"" $5 "\"" OFS # Category # Debit = OUT, Credit = IN direction=($6 ~ /[1-9]/ ? "OUT" : "IN") # Amount - if (direction == "OUT") {printf $6 FS} # Debit - else {printf $7 FS} # Credit + if (direction == "OUT") {printf $6 OFS} # Debit + else {printf $7 OFS} # Credit printf direction OFS printf global_subaccount printf "\n" - }' FS=, OFS=, "$global_in_path" >"$global_out_path" + }' OFS=, "$global_in_path" >"$global_out_path" } function parse_bank() { lib_preprocess::assert_header "Account Number,Transaction Description,Transaction Date,Transaction Type,Transaction Amount,Balance" - gawk -v global_year="$global_year" -v global_subaccount="$global_subaccount" \ + gawk --csv \ + -v global_year="$global_year" \ + -v global_subaccount="$global_subaccount" \ '{ if (NR>1 || NF) { @@ -88,11 +94,13 @@ function parse_bank() printf $1 OFS # Account Number + # Transaction Description sub(/%/, "%%", $2) - printf $2 OFS # Transaction Description + gsub(/"/, "", $2) + printf "\"" $2 "\"" OFS printf $3 OFS # Transaction Date - printf $4 OFS # Transaction Type + printf "\"" $4 "\"" OFS # Transaction Type printf $5 OFS # Transaction Amount printf $6 OFS # Balance @@ -104,7 +112,7 @@ function parse_bank() printf "\n" } - }' FS=, OFS=, "$global_in_path" >"$global_out_path" + }' OFS=, "$global_in_path" >"$global_out_path" } function main()