container: hledger-flow: discover: add uniform quotes

- Allows undesirable characters in variable-text columns
- Related refactoring
This commit is contained in:
2026-02-13 11:04:58 -08:00
parent dadb54d45d
commit 8efbec30cd

View File

@@ -40,7 +40,9 @@ function parse_credit()
# NOTE: sed needed to remove CR. TODO: use gawk # NOTE: sed needed to remove CR. TODO: use gawk
sed 's:\r::g' "$global_in_path" \ sed 's:\r::g' "$global_in_path" \
| 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 || $1 !~ global_year) if (NR<2 || $1 !~ global_year)
next next
@@ -49,38 +51,42 @@ function parse_credit()
printf $2 OFS # Post Date printf $2 OFS # Post Date
# Description # Description
gsub(/, /, " ") # may have comma(s) followed by space sub(/%/, "%%", $3)
sub(/%/, "%%", $3) # remove potential interpretation gsub(/"/, "", $3)
printf $3 OFS printf "\"" $3 "\"" OFS
# Flip the amount signs for proper liabilities accounting # Flip the amount signs for proper liabilities accounting
direction=($4 > 0 ? "OUT" : "IN") direction=($4 > 0 ? "OUT" : "IN")
sub("-", "", $4) sub("-", "", $4)
printf $4 OFS # Amount printf $4 OFS # Amount
printf $5 OFS # Category printf "\"" $5 "\"" OFS # Category
printf direction OFS printf direction OFS
printf global_subaccount printf global_subaccount
printf "\n" printf "\n"
}' FS=, OFS=, >"$global_out_path" }' OFS=, >"$global_out_path"
} }
function parse_bank() function parse_bank()
{ {
lib_preprocess::assert_header "Transaction Date,Transaction Description,Transaction Type,Debit,Credit,Balance" lib_preprocess::assert_header "Transaction Date,Transaction Description,Transaction Type,Debit,Credit,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<2 || $1 !~ global_year) if (NR<2 || $1 !~ global_year)
next next
printf $1 OFS # Transaction Date printf $1 OFS # Transaction Date
# Transaction Description
sub(/%/, "%%", $2) sub(/%/, "%%", $2)
printf $2 OFS # Transaction Description gsub(/"/, "", $2)
printf "\"" $2 "\"" OFS
printf $3 OFS # Transaction Type printf $3 OFS # Transaction Type
@@ -99,7 +105,7 @@ function parse_bank()
printf "\n" printf "\n"
}' FS=, OFS=, "$global_in_path" >"$global_out_path" }' OFS=, "$global_in_path" >"$global_out_path"
} }
function main() function main()