Register/aregister reports in hledger: amounts without commodity?

Hi, folks. I'm preparing reports for someone else. In my reports, I'm valuing all amounts in my home currency (CAD). Is there an option in hledger to format amounts without the commodity symbol "CAD" or do I get to do this with some text manipulation wizardry?

The consumer of my reports will import these register reports into Excel, so I presume it would help if the amounts looked like what Excel believes are numbers.

1 Like

I always do this:

$ hledger reg | sed "%s/ CAD//"

This will do the job, provided that everything ends with CAD. It’s changing every {Whitespace}CAD to nothing(to what’s inside last //). If you want to change something else, you can modify that.

If csv output is needed, this is what you should do:

# sed won't work:
$ hledger reg -O csv -o output.csv | sed "%s/ CAD//"

# Do this instead:
$ hledger reg -O csv | sed "%s/ CAD//" > output.csv

Thank you for confirming. I figured as much, but I thought I’d ask whether hledger does this in a way that I’d be likely to trust more.

As usual, sed fixes all.

1 Like

I ended up here:

sed -e 's/\(\(+|-\)\?\([0-9.,]\)\+\) CAD"/\1"/g'

This assumes that the CSV cells are quoted, which they seem to be. :muscle:

\b (word boundary) can be useful too, as in "\bCAD\b"

You could do it with hledger by converting to the no-symbol commodity. As a (bash) one-liner:

hledger -f $LEDGER_FILE -f <(echo 'P 0000-01-01 CAD 1 ""') -X "" reg
1 Like