Question

62 views
Skip to first unread message

o1bigtenor

unread,
Dec 22, 2019, 7:14:29 AM12/22/19
to ledge...@googlegroups.com
Greetings

I have been using ledger for a bit and am just starting to use more of
its features.
There seems to be always more there to explore and I do appreciate
that the information is so readily accessible after entry.

Am wanting to find some way of reducing some tedium and I either am
not understanding or not finding in the manual or what have you - - -
- so I turn to the group hoping that someone has done similar.

My record keeping system is a little complex and I have lots of levels
of sub-accounts. As I'm doing my 'do the taxes trick' life would be
quite a bit simpler if I could total the amounts in all the levels of
sub-accounts under a particular account.

$ ledger reg -f /home/memyself/ledger2014-19.dat 9795.00.66.01 -b
2019.01.01 -e 2019.12.31

This gives me a listing of all transactions in account 9795.00.66.01
and a summing of the various transactions - - - - that's already
useful.

Now 9795.00.66.01 is a sub-account in a group that starts at
9795.00.00.00 (The major sub-account) and runs to 9795.00.98.50 with
presently 57 sub-accounts.

Have been looking at the 'depth' command. That command, if I
understand correctly, just limits
the depth of the account tree. (My account tree can have a lot more
than a few levels of depth.)
I don't think that command will give me what I'm wanting.

Is there some way to ask ledger to print and sum all the transactions
from 9795.00.00.00 to 9795.00.98.50?

TIA

Richard Lawrence

unread,
Dec 22, 2019, 10:47:05 AM12/22/19
to o1bigtenor, ledge...@googlegroups.com
o1bigtenor <o1big...@gmail.com> writes:

> My record keeping system is a little complex and I have lots of levels
> of sub-accounts. As I'm doing my 'do the taxes trick' life would be
> quite a bit simpler if I could total the amounts in all the levels of
> sub-accounts under a particular account.
>
> Now 9795.00.66.01 is a sub-account in a group that starts at
> 9795.00.00.00 (The major sub-account) and runs to 9795.00.98.50 with
> presently 57 sub-accounts.
>
> Is there some way to ask ledger to print and sum all the transactions
> from 9795.00.00.00 to 9795.00.98.50?

The best way I know to do this would be to use the --limit flag with an
expression that matches just the accounts you want to sum.

I don't know that ledger has a good way of treating account names as
numbers inside an expression, and I suspect that you will end up
fighting with ledger a lot if your accounts tree is based on assuming
that it can.

But at least in this case you can fake it with regexps:

ledger reg --limit 'account =~ /9795\.00\.[0-9][0-8]\.(([0-4][0-9])|50)/'

Hope that helps!

--
Best,
Richard

Richard Lawrence

unread,
Dec 23, 2019, 5:59:25 AM12/23/19
to o1bigtenor, Ledger
o1bigtenor <o1big...@gmail.com> writes:

> On Sun, Dec 22, 2019 at 9:47 AM Richard Lawrence <wyl...@gmail.com> wrote:

>> But at least in this case you can fake it with regexps:
>>
>> ledger reg --limit 'account =~ /9795\.00\.[0-9][0-8]\.(([0-4][0-9])|50)/'
>>

> Could you possible explain the part from the first '/' - - - - or - -
> - -point me
> to a reasonably decent guide on how to do this?

I'm not quite sure I understand the question.

'account =~ /something/' is ledger's syntax for an expression that is
true if the account name in a posting matches the regular expression
"something" (the regular expression is everything between the '/'
characters). See section 11.4, "Complex expressions", in the manual.

Basically, the regular expression I gave you says: match any account name

- that starts exactly with '9795.00.'
- followed by two digits, where the second digit maxes out at '8'
- followed by '.'
- followed by two digits, where either the two match exactly '50', or
the first maxes out at '4' and the second maxes out at '9'

Is that the explanation you're looking for?

If you don't know how to write regular expressions like this, there are
zillions of guides out there -- you can search the web for one that
works well for you.

This is a pretty cumbersome way to filter on account names, though! If I
were you, I would use human-readable strings as account names, because
it's much easier to filter text with regular expressions (which is
pretty much the only way ledger has to filter by account, as far as I
know).

If you really want to filter using the numbering system you've
developed, you might consider putting those numbers in a metadata field
where you can actually use them as numbers. For example, if you put the
number as the value of a tag in a posting, like

2019/12/12 Some postings
expenses:Something €3.00 ; AcctNum: 9795006948
expenses:Something €4.00 ; AcctNum: 9795006928
assets:Cash

then you can use a value expression like

to_int(tag("AcctNum")) > 9795006929

as the argument to --limit, which will in this case show you just the
first posting for €3.00. I'd recommend looking over the EXPRESSIONS
section in the ledger manual page to see what other possibilities might
work for you.

Hope that's helpful!

--
Best,
Richard

o1bigtenor

unread,
Dec 23, 2019, 7:45:18 AM12/23/19
to ledge...@googlegroups.com
On Mon, Dec 23, 2019 at 4:59 AM Richard Lawrence <wyl...@gmail.com> wrote:
>
> o1bigtenor <o1big...@gmail.com> writes:
>
> > On Sun, Dec 22, 2019 at 9:47 AM Richard Lawrence <wyl...@gmail.com> wrote:
>
> >> But at least in this case you can fake it with regexps:
> >>
> >> ledger reg --limit 'account =~ /9795\.00\.[0-9][0-8]\.(([0-4][0-9])|50)/'
> >>
>
> > Could you possible explain the part from the first '/' - - - - or - -
> > - -point me
> > to a reasonably decent guide on how to do this?
>
> I'm not quite sure I understand the question.
>
> 'account =~ /something/' is ledger's syntax for an expression that is
> true if the account name in a posting matches the regular expression
> "something" (the regular expression is everything between the '/'
> characters). See section 11.4, "Complex expressions", in the manual.
>
> Basically, the regular expression I gave you says: match any account name
>
> - that starts exactly with '9795.00.'
> - followed by two digits, where the second digit maxes out at '8'
> - followed by '.'
> - followed by two digits, where either the two match exactly '50', or
> the first maxes out at '4' and the second maxes out at '9'
>
> Is that the explanation you're looking for?

This was what I was looking for - - - thank you!
>
> If you don't know how to write regular expressions like this, there are
> zillions of guides out there -- you can search the web for one that
> works well for you.

I had done some looking and wasn't finding anything that was as
succinct as what you gave above. Trying to learn how to use a computer
language thoroughly in a few hours is not easy and your explanation has
enough information so that I could rewrite what you offered to fit the other
instances that I need it. Likely what I'll be doing is rewriting the expression
to make it quite generic (subaccounts can range to 99) and then just
save the expressions as a group for use when I'm doing my record keeping.

The only concern I have is that I have no real way of 'error checking' what
I will produce but that might be an exercise in doing lots of addition
- - - grin.

>
> This is a pretty cumbersome way to filter on account names, though! If I
> were you, I would use human-readable strings as account names, because
> it's much easier to filter text with regular expressions (which is
> pretty much the only way ledger has to filter by account, as far as I
> know).

Hmmmmmmmmm - - - - as to the numbers being cumbersome - - - I will
translate one number into its 'human readable' text:
Machinery fuel and lubricants: Lubricants: chain saw bar lube oil: winter oil
or numerically 9794.20.91.02
I am already using about 95 columns for my text file - - - - if I were
to want to
go to the expanded text system I would need likely about 160.

if you've ever run into 'GIFI codes' (General Index of Financial Information'
IIRC) you would recognize the first 4 digits - - - they are for machinery fuel
and lubricants - - - - the following are my attempt at devising an account
system.

>
> If you really want to filter using the numbering system you've
> developed, you might consider putting those numbers in a metadata field
> where you can actually use them as numbers. For example, if you put the
> number as the value of a tag in a posting, like
>
> 2019/12/12 Some postings
> expenses:Something €3.00 ; AcctNum: 9795006948
> expenses:Something €4.00 ; AcctNum: 9795006928
> assets:Cash
>
> then you can use a value expression like
>
> to_int(tag("AcctNum")) > 9795006929
>
> as the argument to --limit, which will in this case show you just the
> first posting for €3.00. I'd recommend looking over the EXPRESSIONS
> section in the ledger manual page to see what other possibilities might
> work for you.

I am using what looks something like this
2019.12.12 Some posting
expenses: winter bar oil: 9794.20.91.02 $ 3.00
assets: cash: 1001.00.00.01 $
-3.00

>
> Hope that's helpful!

Yes your responses have been very helpful!!!

Thanking you for your sharing - - - - praying for a right wonderful Christmas
and a blessed New Year for you and yours!
Reply all
Reply to author
Forward
0 new messages