Grouping account balances by currency in hledger

If you are displaying current balance of your accounts in hledger, you might need to sort them by amount and currency ("-S" option) and also separate account groups by currency/commodity using an empty line to increase readability.

Let's use an example journal file from the previous post and display balance of the Assets and Liabilities accounts:

Separating  account groups by currency with a new line can be accomplished using the following AWK script:

Packing it into a one-liner:

This improves readability of the output if you tend to pay more attention to accounts in your main currency.