forked from EvergreenCrypto/docker-finance
container: hledger-flow: discover: add uniform quotes
- Allows undesirable characters in variable-text columns - Related refactoring
This commit is contained in:
@@ -40,7 +40,9 @@ function parse_credit()
|
||||
|
||||
# NOTE: sed needed to remove CR. TODO: use gawk
|
||||
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)
|
||||
next
|
||||
@@ -49,38 +51,42 @@ function parse_credit()
|
||||
printf $2 OFS # Post Date
|
||||
|
||||
# Description
|
||||
gsub(/, /, " ") # may have comma(s) followed by space
|
||||
sub(/%/, "%%", $3) # remove potential interpretation
|
||||
printf $3 OFS
|
||||
sub(/%/, "%%", $3)
|
||||
gsub(/"/, "", $3)
|
||||
printf "\"" $3 "\"" OFS
|
||||
|
||||
# Flip the amount signs for proper liabilities accounting
|
||||
direction=($4 > 0 ? "OUT" : "IN")
|
||||
sub("-", "", $4)
|
||||
printf $4 OFS # Amount
|
||||
|
||||
printf $5 OFS # Category
|
||||
printf "\"" $5 "\"" OFS # Category
|
||||
|
||||
printf direction OFS
|
||||
printf global_subaccount
|
||||
|
||||
printf "\n"
|
||||
|
||||
}' FS=, OFS=, >"$global_out_path"
|
||||
}' OFS=, >"$global_out_path"
|
||||
}
|
||||
|
||||
function parse_bank()
|
||||
{
|
||||
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)
|
||||
next
|
||||
|
||||
printf $1 OFS # Transaction Date
|
||||
|
||||
# Transaction Description
|
||||
sub(/%/, "%%", $2)
|
||||
printf $2 OFS # Transaction Description
|
||||
gsub(/"/, "", $2)
|
||||
printf "\"" $2 "\"" OFS
|
||||
|
||||
printf $3 OFS # Transaction Type
|
||||
|
||||
@@ -99,7 +105,7 @@ function parse_bank()
|
||||
|
||||
printf "\n"
|
||||
|
||||
}' FS=, OFS=, "$global_in_path" >"$global_out_path"
|
||||
}' OFS=, "$global_in_path" >"$global_out_path"
|
||||
}
|
||||
|
||||
function main()
|
||||
|
||||
Reference in New Issue
Block a user