Significant new feature: --group-by=EXPR

35 views
Skip to first unread message

John Wiegley

unread,
May 30, 2010, 5:13:03 AM5/30/10
to ledge...@googlegroups.com
In the 'next' branch there is a new option: --group=by=EXPR. It causes
multiple sub-reports to be generated, one for each varying value of
EXPR. In cases where EXPR returns a null, no report is created.

For example, you can see multiple register reports for the differing
values of the tag "Client" -- and only for transactions which have that
tag -- using:

ledger reg --group-by='tag("Client")'

Or, see which accounts were involved in transactions with what other
accounts:

ledger reg --group-by=account --related --subtotal

In some ways, the use of --group-by=payee could be emulated with a shell
script, for example:

ledger reg -F '%(payee)\n' | sort | \
while read payee ; do \
echo ; echo $payee ; ledger reg payee "/$payee/"; \
done

However, the --group-by option has two main advantages over such
methods:

1. Your data file is only parsed and filtered once, rather than N
times.

2. Ledger knows to ignore null values (which are different from empty
strings and zeroes, something the -F flag can't tell you).

You can use the option --group-title-format to apply underscores to the
group titles, for example:

--group-title-format='%(value)\n%("-" * 79)\n'

Or you can omit group titles altogether with --no-titles. Sometimes,
the titling can be redundant, while most times it is necessary to make
sense of what you're seeing. Note that the "print" report never shows
titles, as the objective of "print" is to always render output that can
be parsed again as input.

John

Reply all
Reply to author
Forward
0 new messages