Report format strings

740 views
Skip to first unread message

Richard Lyons

unread,
Jan 9, 2015, 6:52:28 PM1/9/15
to ledge...@googlegroups.com
Are there anywhere some examples of balance and register format strings?  I am struggling to understand how to alter the defaults from the rather cryptic explanation in the man page.  The minimum I want to achieve is to add the transaction code after the date in the wide standard report format, but ideally I will also adjust column widths to show more of the detail and narrow the cash columns.  I gather that once I have this right, I can add it to my config file.

Craig Earls

unread,
Jan 10, 2015, 12:56:40 AM1/10/15
to ledge...@googlegroups.com
The actual defaults format statements are shown in the ledger manual. 

On Fri, Jan 9, 2015 at 4:52 PM, Richard Lyons <ric...@the-place.net> wrote:
Are there anywhere some examples of balance and register format strings?  I am struggling to understand how to alter the defaults from the rather cryptic explanation in the man page.  The minimum I want to achieve is to add the transaction code after the date in the wide standard report format, but ideally I will also adjust column widths to show more of the detail and narrow the cash columns.  I gather that once I have this right, I can add it to my config file.

--

---
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+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Craig, Corona De Tucson, AZ
enderw88.wordpress.com

Richard Lyons

unread,
Jan 10, 2015, 4:18:20 AM1/10/15
to ledge...@googlegroups.com
Thanks Craig, but I cannot find examples in the man page. I have found on the web (at http://ledger-cli.org/3.0/doc/ledger3.html#Format-Strings) an example, in section 12.4 but this is only of some conditional formatting of one field.  I have tried googling to no avail -- this is made more difficult because the word "ledger" is in common use by all kinds of accounting software.

Alexis

unread,
Jan 10, 2015, 6:00:07 AM1/10/15
to ledge...@googlegroups.com
Hello Richard,
search for --register-format the Output Customization¹ section
of the manual, there you will also find format strings for
other reports which have served me well as learning examples.

If you have any suggestions on how to best improve the documentation for
the format strings please let me know.


Cheers,
Alexis

¹ http://ledger-cli.org/3.0/doc/ledger3.html#Output-customization

Lifepillar

unread,
Jan 10, 2015, 6:07:45 AM1/10/15
to ledge...@googlegroups.com
> Are there anywhere some examples of balance and register format strings?

I don't know how helpful they can be, but you may find some examples in
my ledger2html script:

https://github.com/lifepillar/ledger2html/blob/master/ledger2html

Those are adapted from Ledger's source code to output HTML (wrapping
reports with either <pre> or <table> tags). They also work around some
(but not all) issues with Ledger's default formats, like format errors
that may occur with `ledger budget -X CURRENCY`.

Enjoy,
Life

Richard Lyons

unread,
Jan 10, 2015, 7:09:21 AM1/10/15
to ledge...@googlegroups.com
Thanks.  The manual on the web does give fuller information than the man page. 
Does this mean that I need to copy the whole 31 lines of the register format to
my config file, and edit it? In my case this would be by adding a clause for the
transaction-code, containing something like
  ...justify(truncated(code, int(code_width)),...

richard

Richard Lyons

unread,
Jan 10, 2015, 7:12:21 AM1/10/15
to ledge...@googlegroups.com, lifep...@lifepillar.com
Thanks Lifepillar, they do look useful.

richard

Craig Earls

unread,
Jan 10, 2015, 10:36:24 AM1/10/15
to ledge...@googlegroups.com
Richard, do you have the actual manual?  Not the man page, but the actual pdf or info manual?

--

---
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+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Richard Lyons

unread,
Jan 10, 2015, 6:28:21 PM1/10/15
to ledge...@googlegroups.com
Craig, yes, I have now found the pdf manual, /usr/share/doc/ledger/ledger3.pdf
(and also some info files, but I hate trying to navigate info files).  The very long
register-format is given there too.  There does not seem to be information on
the configuration file, but I assume it can contain command line options simply
omitting the initial "--".  It would be nice to see an example configuration file,
but I suppose trial and error will likely work.  It does not seem to be specified
in the man page, or the manual, but I am assuming ledger looks for
~/.config/ledger/config or ~/.config/ledger.conf or ~/.ledger/config or similar.
I will try copying the default register-format there and begin with arbitrary small
changes.


On Saturday, 10 January 2015 15:36:24 UTC, Craig Earls wrote:
Richard, do you have the actual manual?  Not the man page, but the actual pdf or info manual?

Alexis

unread,
Jan 10, 2015, 6:49:39 PM1/10/15
to ledge...@googlegroups.com
Hi Richard,
> omitting the initial "--". It would be nice to see an example
> configuration file,

To quote from the manual:

--init-file FILE
-i FILE
Causes FILE to be read by ledger before any other ledger file. This
file may not contain any postings, but it may contain option settings.
To specify options in the init file, use the same syntax as on the
command-line, but put each option on its own line. Here is an example
init file:

--price-db ~/finance/.pricedb
--wide
; ~/.ledgerrc ends here

Option settings on the command-line or in the environment always take
precedence over settings in the init file."

(http://ledger-cli.org/3.0/doc/ledger3.html#index-_002d_002dinit_002dfile-FILE-2)

> It does not seem to be specified
> in the man page, or the manual, but I am assuming ledger looks for
> ~/.config/ledger/config or ~/.config/ledger.conf or ~/.ledger/config or
> similar.

It's ~/.ledgerrc
(http://ledger-cli.org/3.0/doc/ledger3.html#index-_002d_002dinit_002dfile-FILE-1)


Cheers,
Alexis

Richard Lyons

unread,
Jan 10, 2015, 7:01:18 PM1/10/15
to ledge...@googlegroups.com
Thanks Alexis.
I searched for "config" -- did not think if "init".  I shall
start experimenting with ~/.ledgerrc tomorrow. 

richard

On Saturday, 10 January 2015 23:49:39 UTC, unices wrote:
[...]

Richard Lyons

unread,
Jan 11, 2015, 8:02:56 AM1/11/15
to ledge...@googlegroups.com
Well, I am getting nowhere with this.  I tried copying the full default
format string for register-format as given in the manual to my .ledgerrc.
It has to be joined up into a single line.  But it throws an error
"Error: Invalid char '\'"
and I see that the last 6 or 7 lines of the
format string include several backslash-escaped characters, including
double quotes and a newline.  I cannot really see what that segment of the
sting is doing anyway.  Unless there are any useful examples available,
I will have to abandon trying to include the code field in the register.

I assume perhaps the -w parameter changes the various default field widths
in some hard-coded way, but have no idea whether the variable code-width is
even defined anywhere, as I do not see this field in any report.

richard




Alexis

unread,
Jan 11, 2015, 8:36:07 AM1/11/15
to ledge...@googlegroups.com
Hi Richard,
I've copied the register-format string from the manual and put it
into a lyons.ledgerrc file
https://gist.githubusercontent.com/afh/1b7d85928f464c99bcee/raw/707d3963f9cd5eccc41dc60e2a7a737ed20b2373/lyons.ledgerrc

When I run ledger --init-file lyons.ledgerrc test/input/sample.dat
I see the familiar register output.

When I start editing lyons.ledgerrc I can change the register output
to my heart's desire. Please download the above gist and store
it as a .ledgerrc and retry.


Hope this helps,
Alexis

Richard Lyons

unread,
Jan 11, 2015, 9:06:51 AM1/11/15
to ledge...@googlegroups.com
Thanks again Alexis.  It was only the escaped quotes that caused errors
then.  The "\n" is accepted. What you posted is the same as the pdf manual
but without the enclosing quotes and the four backslash escapes. 

And experiment reveals "code-width" is not defined, but I found that
I can put an integer in the string instead, and get the required result. So
that basically solves the problem I was having. 

Thanks to all who helped.


richard
Reply all
Reply to author
Forward
0 new messages