Update: I'm now using ledger's built-in parser to losslessly edit ledger
journal files.  I've updated the gist[1].  You can use it like this:

    from ledgerparser import parse_xacts
    
    xacts = parse_xacts(ledger_file)
    for lines, xact in xacts:
                if xact...:  # this is the xact you're looking for
                        for line in lines:
                                # edit the line however you want using re.sub 
or whatever
                                sys.stdout.write(line)


On Mon, Sep 05, 2016 at 01:53:12PM -0500, Ryan Nowakowski wrote:
> I'm building a tool for automatically categorizing transactions based 
> on regex matching certain journal fields.  It's a standard UNIX filter
> that takes a journal file from stdin, modifies it and sends it to stdout.
> I want to maintain the exact format of the journal including comments.
> I haven't figured out a way to do this with the ledger parser python lib
> so I wrote my own[1].  Does anyone else have a better way to do this?
> I'd rather not maintain my own parser.
> 
> Thanks!
> 
> Ryan
> 
> [1] https://gist.github.com/tubaman/0e80cec388d3d5d61e3f300e2477a9ae

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/20210528230257.GD9968%40fattuba.com.

Reply via email to