Here is some code to do mostly that. Use is to run it with Python 3, first argument is source file, second argument is output file for matched transactions, third is output file for non-matched transactions, and the fourth and so on are text strings that, if found, will add to the matched, and if not found, will add to the non-matched output.

#!/usr/bin/python3

import sys

matchers = sys.argv[4:]
infile = open(sys.argv[1], "r")
chunk = None
lastone = None

def match(text):
    return all (m in text for m in matchers)


def start_condition(line):
    return line.startswith("20") or line.startswith(";")

def end_condition(line):
    return not bool(line.rstrip("\n"))


with open(sys.argv[2], "w") as matched:
    with open(sys.argv[3], "w") as notmatched:
        for line in infile:
            if chunk is not None:
                chunk += line
                if end_condition(line):
                    # Chunk over.  We print.
                    lastone = (matched if match(chunk) else notmatched)
                    lastone.write(chunk)
                    chunk = None
            else:
                if start_condition(line):
                    chunk = line
                else:
                    matched.write(line)
                    notmatched.write(line)

        if chunk is not None:
            (matched if match(chunk) else notmatched).write(chunk)


On 20/12/2019 15.30, nug get wrote:
thanks, a python script would probably do it in the end.
is there a beancount function that would return all objects in my ledger file as list or something? Writing that myself would be beyond my current capabilities, or of irresponsible effort timewise :)



On Friday, 20 December 2019 13:57:54 UTC+1, Martin Blais wrote:

    You will want to write a little python script.
    I would operate on source code, not on the data structures, so you
    keep the original formatting and metadata and comments

    On Fri, Dec 20, 2019, 06:59 nug get <[email protected]
    <javascript:>> wrote:

        Is there a feature that would allow me to sort the
        transactions in my files, for example by date, or specific
        accounts?
        Thanks!

        Background:
        I migrated my 3 years of Gnucash records to beancount. It's
        all one long list of transactions sorted by date. I'd like to
        separate my cash and bank account transactions into two
        different files.

-- You received this message because you are subscribed to the
        Google Groups "Beancount" group.
        To unsubscribe from this group and stop receiving emails from
        it, send an email to [email protected] <javascript:>.
        To view this discussion on the web visit
        
https://groups.google.com/d/msgid/beancount/4b6c37cd-dab7-4683-80fc-e6affac7e1ca%40googlegroups.com
        
<https://groups.google.com/d/msgid/beancount/4b6c37cd-dab7-4683-80fc-e6affac7e1ca%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "Beancount" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/a728b410-6f4d-4623-b7fb-e40d03eb0cf8%40googlegroups.com <https://groups.google.com/d/msgid/beancount/a728b410-6f4d-4623-b7fb-e40d03eb0cf8%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Rudd-O
    http://rudd-o.com/

--
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/d117b6cb-67e1-3e59-1c39-928cee0672a7%40rudd-o.com.

Attachment: OpenPGP_0x5C06F67A8BDEBA09_and_old_rev.asc
Description: application/pgp-keys

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to