You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将hledger日记账中的过账对齐到指定列

统一对齐hledger日记账中的金额列

这是《Right justify amounts in hledger journal text file》的跟进需求:hledger是一款纯文本会计CLI工具,它仅能对齐单笔交易内的过账条目,但无法将整个日记账里的所有过账金额统一对齐到指定列。

现在需要实现的效果是:调整缩进账户名称与右侧金额之间的空格,让所有金额对齐到同一列。这类需求用awk、printf这类命令行工具即可完成,输入输出示例如下:

输入示例

# Test journal

; To test right-alignment of amounts



* Transactions

2018-01-01 @Payee | Internet
    expenses:communication:internet      123.00 EUR
    assets:cash:eur

2018-01-01 @Landlady | Rent
    expenses:housing:rent      321.00 EUR
    expenses:fees                2.50 EUR  ; Bank fee
    assets:bank:eur           -323.50 EUR

2016/01/01 Unit prices
   Expense:Foo  56 @ $6.00 ; a comment after a space
   Cash  $-336  ; a comment after two spaces

2022-01-01 Time
    skill      10000h
    time      -10000h
   weird    ; weird comment on posting without amount

2018-01-01 @Some things in life | Are free
    ; With and without comment
    expenses:misc:stuff                                       0  ; A comment
    expenses:misc:things                                      0
    assets:cash:eur

输出示例

# Test journal

; To test right-alignment of amounts



* Transactions

2018-01-01 @Payee | Internet
    expenses:communication:internet       123.00 EUR
    assets:cash:eur

2018-01-01 @Landlady | Rent
    expenses:housing:rent                 321.00 EUR
    expenses:fees                           2.50 EUR  ; Bank fee
    assets:bank:eur                      -323.50 EUR

2016/01/01 Unit prices
   Expense:Foo                            56 @ $6.00 ; a comment after a space
   Cash                                        $-336  ; a comment after two spaces

2022-01-01 Time
    skill                                     10000h
    time                                     -10000h
   weird                                            ; weird comment on posting without amount

2018-01-01 @Some things in life | Are free
    ; With and without comment
    expenses:misc:stuff                            0  ; A comment
    expenses:misc:things                           0
    assets:cash:eur

内容的提问来源于stack exchange,提问作者Leeroy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 02:56:13