2

Ledger (http://ledger-cli.org/) allows to output reverse sorted balance of your Income accounts using the following command:

ledger -f money.txt bal Income --sort "-abs(total)"

so the output looks like follows:

  $-7,715.00  Income
  $-6,789.10    Payroll
    $-567.89    Insurance
    $-234.56    Gift Card
    $-200.56      Store 1  
     $-34.00      Store 2
    $-123.45    Coupons

Is there a way to output the same information in CSV format, but keeping the indentation of the categories as follows (header values are not important)?

    "Amount","Level 1","Level 2,"Level 3"
    $-7,715.00,Income,,
    ,$-6,789.10,Payroll,
    ,$-567.89,Insurance,
    ,$-234.56,Gift Card,
    ,,$-200.56,Store 1
    ,,$-34.00,Store 2
    ,$-123.45,Coupons,
1
  • 2
    I'm voting to close this question as off-topic because it is about coding.
    – Michael
    Sep 5, 2017 at 13:45

1 Answer 1

2

The Ledger documentation says that it has a csv command built in, so you could try that.

Alternatively it would be quite easy to post-process the type of output you have provided to the format you want. Tools such as sed or awk would do this for you.

3
  • Unfortunately csv command is a bit limited for this kind of operation. Yes sed/awk can certainly achieve that, I was hoping to get it working by the means of ledger itself, since running it in Windows environment.
    – Altair7852
    Sep 10, 2017 at 16:19
  • 1
    Heading rapidly off topic, but you can get Unix utilities for Windows (without having to install Cygwin etc.) - I use them a lot. Search for UnixUtils or GnuWin32.
    – Vicky
    Sep 10, 2017 at 17:21
  • I end up doing it manually through excel, which is ugly. Will look into UnixUtils - good idea!
    – Altair7852
    Sep 10, 2017 at 18:46

Not the answer you're looking for? Browse other questions tagged .