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:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[johndoe@ArchLinux]% hledger -f Finances_2021.journal balance -S "acct:(Assets|Liabilities)"
15 VHT Assets:US:ETrade:VHT
16 VEA Assets:US:ETrade:VEA
70.356 VBMPX Assets:US:Vanguard:VBMPX
120 VACHR Assets:US:Hoogle:Vacation
6656.17 USD Assets:US:ETrade:Cash
248.75 USD Assets:US:BofA:Checking
-0.11 USD Assets:US:Vanguard:Cash
-1054.87 USD Liabilities:US:Chase:Slate
98.915 RGAGX Assets:US:Vanguard:RGAGX
20 ITOT Assets:US:ETrade:ITOT
41 GLD Assets:US:ETrade:GLD
--------------------
41 GLD
20 ITOT
98.915 RGAGX
5849.94 USD
120 VACHR
70.356 VBMPX
16 VEA
15 VHT
|
Separating account groups by currency with a new line can be accomplished using the following AWK script:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
[johndoe@ArchLinux]% hledger -f Finances_2021.journal balance -S "acct:(Assets|Liabilities)" | \
awk 'BEGIN{state="div"; prev=""}{ \
if (($1 !~ "---") && (state == "div")){ \
if ($2 != prev){ \
printf("\n%s\n", $0) \
} else { \
print $0 \
} \
prev = $2 \
} \
if (state == "stop"){ \
print $0 \
} \
if ($1 ~ "---"){ \
print $0; \
state = "stop" \
} \
}'
15 VHT Assets:US:ETrade:VHT
16 VEA Assets:US:ETrade:VEA
70.356 VBMPX Assets:US:Vanguard:VBMPX
120 VACHR Assets:US:Hoogle:Vacation
6656.17 USD Assets:US:ETrade:Cash
248.75 USD Assets:US:BofA:Checking
-0.11 USD Assets:US:Vanguard:Cash
-1054.87 USD Liabilities:US:Chase:Slate
98.915 RGAGX Assets:US:Vanguard:RGAGX
20 ITOT Assets:US:ETrade:ITOT
41 GLD Assets:US:ETrade:GLD
--------------------
41 GLD
20 ITOT
98.915 RGAGX
5849.94 USD
120 VACHR
70.356 VBMPX
16 VEA
15 VHT
|
Packing it into a one-liner:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
[johndoe@ArchLinux]% hledger -f Finances_2021.journal balance -S "acct:(Assets|Liabilities)" | awk 'BEGIN{state="div"; prev=""}{if (($1 !~ "---") && (state == "div")){if ($2 != prev){printf("\n%s\n",$0)} else {print}; prev = $2}; if (state == "stop"){print}; if ($1 ~ "---"){print; state = "stop"}}'
15 VHT Assets:US:ETrade:VHT
16 VEA Assets:US:ETrade:VEA
70.356 VBMPX Assets:US:Vanguard:VBMPX
120 VACHR Assets:US:Hoogle:Vacation
6656.17 USD Assets:US:ETrade:Cash
248.75 USD Assets:US:BofA:Checking
-0.11 USD Assets:US:Vanguard:Cash
-1054.87 USD Liabilities:US:Chase:Slate
98.915 RGAGX Assets:US:Vanguard:RGAGX
20 ITOT Assets:US:ETrade:ITOT
41 GLD Assets:US:ETrade:GLD
--------------------
41 GLD
20 ITOT
98.915 RGAGX
5849.94 USD
120 VACHR
70.356 VBMPX
16 VEA
15 VHT
|
This improves readability of the output if you tend to pay more attention to accounts in your main currency.