Function to regex match accounts in a transaction?

83 views
Skip to first unread message

Martin Michlmayr

unread,
Oct 30, 2022, 1:18:30 AM10/30/22
to ledge...@googlegroups.com
"any(account =~ /Ass/)" is a boolean. Is there a way to do a regex on
all accounts in a transaction and get a string as a result?

Use case: imagine you receive Income:Dividends on two accounts:
Assets:Broker 1 and Assets:Broker 2

You want to --group-by the Assets: account to find on which broker
account you received dividends, e.g.:

bal Income:Dividends --group-by get_account("^Assets:Broker")

Inspired by this question:
https://www.reddit.com/r/plaintextaccounting/comments/yedxd8/grouping_balances_by_target_account/

--
Martin Michlmayr
https://www.cyrius.com/

John Wiegley

unread,
Oct 30, 2022, 6:21:58 PM10/30/22
to Martin Michlmayr, ledge...@googlegroups.com
>>>>> Martin Michlmayr <t...@cyrius.com> writes:

> You want to --group-by the Assets: account to find on which broker account
> you received dividends, e.g.:

> bal Income:Dividends --group-by get_account("^Assets:Broker")

I'm not sure this means what you expect it to mean...

--group-by EXPR evaluates EXPR *for every entry in the report* and then groups
the results by the strings yielded from that evaluation.

What you seem to want is this:

1. for an entry that matches account X
2. filter the *other* posts in that transaction by those matching account Y
3. use the (assumed single) account name resulting from this for grouping

This can't be done with Ledger's command-line option, although it would be
possible as a Python script.

John
Reply all
Reply to author
Forward
0 new messages