hledger
hledger copied to clipboard
[CSV rules] Custom field assignment under if statement
Hi, thanks for this brilliant tool!
Problem How to assign a value to a custom field (not hledger one)? So far it breaks with strange error.
Motivation I've tried to parse a complex csv file from a bank (broker). It has different fields for in and out amounts which can be both non empty (two transactions) and different currencies. Also in my hledger journals I use other symbols for currencies and placement: 1000 D (instead of $1000), i.e. after amount.
My csv file:
agreement currency Дата Операция Сумма зачисления Сумма списания В т.ч.НДС (руб.) Остаток (+/-) в т.ч. гарант. обеспечение в т.ч. депозитная маржа Площадка Примечание Промежуточный клиринг (FORTS)
myaggrementname от 06.04.2020 Рубль 11.06.20 """Проценты по займам """"овернайт ЦБ""""""" 0.04 ММВБ
My rules file:
separator TAB
skip 1
fields aggrement, rc, , date, tname, , , , t_in, t_out
if %rc USD
mycurrency D
if %rc Рубль
mycurrency R
if %t_in .+
amount-in %t_in %mycurrency
if %t_out .+
amount-out %t_out %mycurrency
Steps to reproduce. Just run
[I] ➜ hledger -f test.csv print --rules-file csv.rules
hledger: user error (csv.rules:8:1:
|
8 | if %rc USD
| ^
unexpected 'i'
expecting end of input
)
Misc. hledger 1.17.1.1 (The same under 1.18)