D Directive vs commodity declaration

15 views
Skip to first unread message

Paul Marriott

unread,
Feb 11, 2023, 5:25:42 PMFeb 11
to hledger
I have just moved from beancount to hledger and am a bit confused with to properly make use of the D directive and commodity directive.

I would like to be able to keep beancount's USD commodity, accept amounts without a commodity as USD and output USD amounts as $ in reports.

I have tried various combinations of D directive and commodity declarations, but cannot seem to make it work.  Can someone explain best approach, short of stripping out all the USD's from my files?

Thanks


Simon Michael

unread,
Feb 11, 2023, 5:54:40 PMFeb 11
to hledger
Welcome,

There's no built-in way to transform a commodity symbol (from USD to $). The best thing would be to replace it globally in your files. Or more temporarily, to preprocess:

sed -E -e 's/\bUSD\b/$/g' $LEDGER_FILE | hledger -f- ...

or post-process:

hledger ... | sed ...

Paul Marriott

unread,
Feb 11, 2023, 7:37:32 PMFeb 11
to hledger
I went ahead and stripped out all the USD's and added a D directive.  Since I have several include flies, I found I had to add a D directive at the head of each, but have everything working now.
Thanks

Reply all
Reply to author
Forward
0 new messages