From 0bf0c30b8de97b04f25c5f85f03bc686a1bb024c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 22 Nov 2023 22:56:31 -1000 Subject: [PATCH] doc: update manuals --- hledger-lib/.date.m4 | 2 +- hledger-ui/.date.m4 | 2 +- hledger-ui/hledger-ui.1 | 46 +- hledger-ui/hledger-ui.info | 91 +- hledger-ui/hledger-ui.txt | 36 +- hledger-web/.date.m4 | 2 +- hledger-web/hledger-web.1 | 13 +- hledger-web/hledger-web.info | 55 +- hledger-web/hledger-web.txt | 13 +- hledger/.date.m4 | 2 +- hledger/hledger.1 | 839 ++++++---- hledger/hledger.info | 2332 ++++++++++++++------------ hledger/hledger.txt | 2988 ++++++++++++++++++---------------- 13 files changed, 3461 insertions(+), 2960 deletions(-) diff --git a/hledger-lib/.date.m4 b/hledger-lib/.date.m4 index 38fac93ee..52c2fb8c0 100644 --- a/hledger-lib/.date.m4 +++ b/hledger-lib/.date.m4 @@ -1,2 +1,2 @@ m4_dnl Date to show in man pages. Updated by "Shake manuals" -m4_define({{_monthyear_}}, {{September 2023}})m4_dnl +m4_define({{_monthyear_}}, {{November 2023}})m4_dnl diff --git a/hledger-ui/.date.m4 b/hledger-ui/.date.m4 index 38fac93ee..52c2fb8c0 100644 --- a/hledger-ui/.date.m4 +++ b/hledger-ui/.date.m4 @@ -1,2 +1,2 @@ m4_dnl Date to show in man pages. Updated by "Shake manuals" -m4_define({{_monthyear_}}, {{September 2023}})m4_dnl +m4_define({{_monthyear_}}, {{November 2023}})m4_dnl diff --git a/hledger-ui/hledger-ui.1 b/hledger-ui/hledger-ui.1 index 198b26ade..a52cff8e5 100644 --- a/hledger-ui/hledger-ui.1 +++ b/hledger-ui/hledger-ui.1 @@ -1,5 +1,5 @@ -.TH "HLEDGER-UI" "1" "September 2023" "hledger-ui-1.31.99 " "hledger User Manuals" +.TH "HLEDGER-UI" "1" "November 2023" "hledger-ui-1.31.99 " "hledger User Manuals" @@ -347,25 +347,28 @@ current transaction when invoked from the register and transaction screens, and at the error location (if possible) when invoked from the error screen. .PP -\f[V]B\f[R] toggles cost mode, showing amounts in their cost\[aq]s -commodity (like toggling the \f[V]-B/--cost\f[R] flag). +\f[V]B\f[R] toggles cost mode, showing amounts converted to their +cost\[aq]s commodity (see hledger manual > Cost reporting. .PP -\f[V]V\f[R] toggles value mode, showing amounts\[aq] current market -value in their default valuation commodity (like toggling the -\f[V]-V/--market\f[R] flag). -Note, \[dq]current market value\[dq] means the value on the report end -date if specified, otherwise today. -To see the value on another date, you can temporarily set that as the -report end date. -Eg: to see a transaction as it was valued on july 30, go to the accounts -or register screen, press \f[V]/\f[R], and add \f[V]date:-7/30\f[R] to -the query. +\f[V]V\f[R] toggles value mode, showing amounts converted to their +market value (see hledger manual > Valuation flag). +More specifically, +.IP "1." 3 +By default, the \f[V]V\f[R] key toggles showing end value +(\f[V]--value=end\f[R]) on or off. +The valuation date will be the report end date if specified, otherwise +today. +.IP "2." 3 +If you started hledger-ui with some other valuation (such as +\f[V]--value=then,EUR\f[R]), the \f[V]V\f[R] key toggles that off or on. .PP -At most one of cost or value mode can be active at once. -.PP -There\[aq]s not yet any visual reminder when cost or value mode is -active; for now pressing \f[V]b\f[R] \f[V]b\f[R] \f[V]v\f[R] should -reliably reset to normal mode. +Cost/value tips: - When showing end value, you can change the report end +date without restarting, by pressing \f[V]/\f[R] and adding a query like +\f[V]date:..YYYY-MM-DD\f[R]. +- Either cost mode, or value mode, can be active, but not both at once. +Cost mode takes precedence. +- There\[aq]s not yet any visual indicator that cost or value mode is +active, other than the amount values. .PP \f[V]q\f[R] quits the application. .PP @@ -436,6 +439,13 @@ This will be the running historical balance (what you would see on a bank\[aq]s website, eg) if not disturbed by a query. .RE .PP +Note, this screen combines each transaction\[aq]s in-period postings to +a single line item, dated with the earliest in-period transaction or +posting date (like hledger\[aq]s \f[V]aregister\f[R]). +So custom posting dates can cause the running balance to be temporarily +inaccurate. +(See hledger manual > aregister and posting dates.) +.PP Transactions affecting this account\[aq]s subaccounts will be included in the register if the accounts screen is in tree mode, or if it\[aq]s in list mode but this account has subaccounts which are not shown due to diff --git a/hledger-ui/hledger-ui.info b/hledger-ui/hledger-ui.info index b1547951b..f8887c1a6 100644 --- a/hledger-ui/hledger-ui.info +++ b/hledger-ui/hledger-ui.info @@ -377,22 +377,25 @@ cursor will be positioned at the current transaction when invoked from the register and transaction screens, and at the error location (if possible) when invoked from the error screen. - 'B' toggles cost mode, showing amounts in their cost's commodity -(like toggling the '-B/--cost' flag). + 'B' toggles cost mode, showing amounts converted to their cost's +commodity (see hledger manual > Cost reporting. - 'V' toggles value mode, showing amounts' current market value in -their default valuation commodity (like toggling the '-V/--market' -flag). Note, "current market value" means the value on the report end -date if specified, otherwise today. To see the value on another date, -you can temporarily set that as the report end date. Eg: to see a -transaction as it was valued on july 30, go to the accounts or register -screen, press '/', and add 'date:-7/30' to the query. + 'V' toggles value mode, showing amounts converted to their market +value (see hledger manual > Valuation flag). More specifically, - At most one of cost or value mode can be active at once. + 1. By default, the 'V' key toggles showing end value ('--value=end') + on or off. The valuation date will be the report end date if + specified, otherwise today. - There's not yet any visual reminder when cost or value mode is -active; for now pressing 'b' 'b' 'v' should reliably reset to normal -mode. + 2. If you started hledger-ui with some other valuation (such as + '--value=then,EUR'), the 'V' key toggles that off or on. + + Cost/value tips: - When showing end value, you can change the report +end date without restarting, by pressing '/' and adding a query like +'date:..YYYY-MM-DD'. - Either cost mode, or value mode, can be active, +but not both at once. Cost mode takes precedence. - There's not yet +any visual indicator that cost or value mode is active, other than the +amount values. 'q' quits the application. @@ -500,6 +503,12 @@ line represents one transaction, and shows: historical balance (what you would see on a bank's website, eg) if not disturbed by a query. + Note, this screen combines each transaction's in-period postings to a +single line item, dated with the earliest in-period transaction or +posting date (like hledger's 'aregister'). So custom posting dates can +cause the running balance to be temporarily inaccurate. (See hledger +manual > aregister and posting dates.) + Transactions affecting this account's subaccounts will be included in the register if the accounts screen is in tree mode, or if it's in list mode but this account has subaccounts which are not shown due to a depth @@ -677,34 +686,34 @@ Node: MOUSE7825 Ref: #mouse7920 Node: KEYS8157 Ref: #keys8250 -Node: SCREENS12763 -Ref: #screens12861 -Node: Menu13441 -Ref: #menu13534 -Node: Cash accounts13729 -Ref: #cash-accounts13871 -Node: Balance sheet accounts14055 -Ref: #balance-sheet-accounts14236 -Node: Income statement accounts14356 -Ref: #income-statement-accounts14542 -Node: All accounts14706 -Ref: #all-accounts14852 -Node: Register15034 -Ref: #register15158 -Node: Transaction17120 -Ref: #transaction17243 -Node: Error18660 -Ref: #error18754 -Node: TIPS18998 -Ref: #tips19097 -Node: Watch mode19139 -Ref: #watch-mode19246 -Node: Debug output20705 -Ref: #debug-output20816 -Node: ENVIRONMENT21028 -Ref: #environment21138 -Node: BUGS21329 -Ref: #bugs21412 +Node: SCREENS12905 +Ref: #screens13003 +Node: Menu13583 +Ref: #menu13676 +Node: Cash accounts13871 +Ref: #cash-accounts14013 +Node: Balance sheet accounts14197 +Ref: #balance-sheet-accounts14378 +Node: Income statement accounts14498 +Ref: #income-statement-accounts14684 +Node: All accounts14848 +Ref: #all-accounts14994 +Node: Register15176 +Ref: #register15300 +Node: Transaction17584 +Ref: #transaction17707 +Node: Error19124 +Ref: #error19218 +Node: TIPS19462 +Ref: #tips19561 +Node: Watch mode19603 +Ref: #watch-mode19710 +Node: Debug output21169 +Ref: #debug-output21280 +Node: ENVIRONMENT21492 +Ref: #environment21602 +Node: BUGS21793 +Ref: #bugs21876  End Tag Table diff --git a/hledger-ui/hledger-ui.txt b/hledger-ui/hledger-ui.txt index 233230f38..c381f10dd 100644 --- a/hledger-ui/hledger-ui.txt +++ b/hledger-ui/hledger-ui.txt @@ -314,21 +314,25 @@ KEYS register and transaction screens, and at the error location (if possi- ble) when invoked from the error screen. - B toggles cost mode, showing amounts in their cost's commodity (like - toggling the -B/--cost flag). + B toggles cost mode, showing amounts converted to their cost's commod- + ity (see hledger manual > Cost reporting. - V toggles value mode, showing amounts' current market value in their - default valuation commodity (like toggling the -V/--market flag). - Note, "current market value" means the value on the report end date if - specified, otherwise today. To see the value on another date, you can - temporarily set that as the report end date. Eg: to see a transaction - as it was valued on july 30, go to the accounts or register screen, - press /, and add date:-7/30 to the query. + V toggles value mode, showing amounts converted to their market value + (see hledger manual > Valuation flag). More specifically, - At most one of cost or value mode can be active at once. + 1. By default, the V key toggles showing end value (--value=end) on or + off. The valuation date will be the report end date if specified, + otherwise today. - There's not yet any visual reminder when cost or value mode is active; - for now pressing b b v should reliably reset to normal mode. + 2. If you started hledger-ui with some other valuation (such as + --value=then,EUR), the V key toggles that off or on. + + Cost/value tips: - When showing end value, you can change the report + end date without restarting, by pressing / and adding a query like + date:..YYYY-MM-DD. - Either cost mode, or value mode, can be active, + but not both at once. Cost mode takes precedence. - There's not yet + any visual indicator that cost or value mode is active, other than the + amount values. q quits the application. @@ -389,6 +393,12 @@ SCREENS (what you would see on a bank's website, eg) if not disturbed by a query. + Note, this screen combines each transaction's in-period postings to a + single line item, dated with the earliest in-period transaction or + posting date (like hledger's aregister). So custom posting dates can + cause the running balance to be temporarily inaccurate. (See hledger + manual > aregister and posting dates.) + Transactions affecting this account's subaccounts will be included in the register if the accounts screen is in tree mode, or if it's in list mode but this account has subaccounts which are not shown due to a @@ -527,4 +537,4 @@ LICENSE SEE ALSO hledger(1), hledger-ui(1), hledger-web(1), ledger(1) -hledger-ui-1.31.99 September 2023 HLEDGER-UI(1) +hledger-ui-1.31.99 November 2023 HLEDGER-UI(1) diff --git a/hledger-web/.date.m4 b/hledger-web/.date.m4 index 38fac93ee..52c2fb8c0 100644 --- a/hledger-web/.date.m4 +++ b/hledger-web/.date.m4 @@ -1,2 +1,2 @@ m4_dnl Date to show in man pages. Updated by "Shake manuals" -m4_define({{_monthyear_}}, {{September 2023}})m4_dnl +m4_define({{_monthyear_}}, {{November 2023}})m4_dnl diff --git a/hledger-web/hledger-web.1 b/hledger-web/hledger-web.1 index ddd8fb668..e840343b1 100644 --- a/hledger-web/hledger-web.1 +++ b/hledger-web/hledger-web.1 @@ -1,5 +1,5 @@ -.TH "HLEDGER-WEB" "1" "September 2023" "hledger-web-1.31.99 " "hledger User Manuals" +.TH "HLEDGER-WEB" "1" "November 2023" "hledger-web-1.31.99 " "hledger User Manuals" @@ -102,12 +102,11 @@ hledger-web normally serves static files itself, but if you wanted to serve them from another server for efficiency, you would set the url with this. .TP -\f[V]--capabilities=CAP[,CAP..]\f[R] -enable the view, add, and/or manage capabilities (default: view,add) -.TP -\f[V]--capabilities-header=HTTPHEADER\f[R] -read capabilities to enable from a HTTP header, like -X-Sandstorm-Permissions (default: disabled) +\f[V]--allow=view|add|edit\f[R] +set the user\[aq]s access level for changing data (default: +\f[V]add\f[R]). +It also accepts \f[V]sandstorm\f[R] for use on that platform (reads +permissions from the \f[V]X-Sandstorm-Permissions\f[R] request header). .TP \f[V]--test\f[R] run hledger-web\[aq]s tests and exit. diff --git a/hledger-web/hledger-web.info b/hledger-web/hledger-web.info index faa649582..ea05b0b0d 100644 --- a/hledger-web/hledger-web.info +++ b/hledger-web/hledger-web.info @@ -110,14 +110,11 @@ will be applied in addition to any search query entered there. normally serves static files itself, but if you wanted to serve them from another server for efficiency, you would set the url with this. -'--capabilities=CAP[,CAP..]' +'--allow=view|add|edit' - enable the view, add, and/or manage capabilities (default: - view,add) -'--capabilities-header=HTTPHEADER' - - read capabilities to enable from a HTTP header, like - X-Sandstorm-Permissions (default: disabled) + set the user's access level for changing data (default: 'add'). It + also accepts 'sandstorm' for use on that platform (reads + permissions from the 'X-Sandstorm-Permissions' request header). '--test' run hledger-web's tests and exit. hspec test runner args may @@ -648,28 +645,28 @@ Tag Table: Node: Top225 Node: OPTIONS2580 Ref: #options2685 -Node: General help options5996 -Ref: #general-help-options6146 -Node: General input options6428 -Ref: #general-input-options6614 -Node: General reporting options7316 -Ref: #general-reporting-options7481 -Node: PERMISSIONS10871 -Ref: #permissions11010 -Node: EDITING UPLOADING DOWNLOADING12222 -Ref: #editing-uploading-downloading12403 -Node: RELOADING13237 -Ref: #reloading13371 -Node: JSON API13804 -Ref: #json-api13919 -Node: DEBUG OUTPUT19407 -Ref: #debug-output19532 -Node: Debug output19559 -Ref: #debug-output-119660 -Node: ENVIRONMENT20077 -Ref: #environment20196 -Node: BUGS20313 -Ref: #bugs20397 +Node: General help options5973 +Ref: #general-help-options6123 +Node: General input options6405 +Ref: #general-input-options6591 +Node: General reporting options7293 +Ref: #general-reporting-options7458 +Node: PERMISSIONS10848 +Ref: #permissions10987 +Node: EDITING UPLOADING DOWNLOADING12199 +Ref: #editing-uploading-downloading12380 +Node: RELOADING13214 +Ref: #reloading13348 +Node: JSON API13781 +Ref: #json-api13896 +Node: DEBUG OUTPUT19384 +Ref: #debug-output19509 +Node: Debug output19536 +Ref: #debug-output-119637 +Node: ENVIRONMENT20054 +Ref: #environment20173 +Node: BUGS20290 +Ref: #bugs20374  End Tag Table diff --git a/hledger-web/hledger-web.txt b/hledger-web/hledger-web.txt index 8ace89e72..b8b0b6d46 100644 --- a/hledger-web/hledger-web.txt +++ b/hledger-web/hledger-web.txt @@ -87,13 +87,10 @@ OPTIONS them from another server for efficiency, you would set the url with this. - --capabilities=CAP[,CAP..] - enable the view, add, and/or manage capabilities (default: - view,add) - - --capabilities-header=HTTPHEADER - read capabilities to enable from a HTTP header, like X-Sand- - storm-Permissions (default: disabled) + --allow=view|add|edit + set the user's access level for changing data (default: add). + It also accepts sandstorm for use on that platform (reads per- + missions from the X-Sandstorm-Permissions request header). --test run hledger-web's tests and exit. hspec test runner args may follow a --, eg: hledger-web --test -- --help @@ -567,4 +564,4 @@ LICENSE SEE ALSO hledger(1), hledger-ui(1), hledger-web(1), ledger(1) -hledger-web-1.31.99 September 2023 HLEDGER-WEB(1) +hledger-web-1.31.99 November 2023 HLEDGER-WEB(1) diff --git a/hledger/.date.m4 b/hledger/.date.m4 index 38fac93ee..52c2fb8c0 100644 --- a/hledger/.date.m4 +++ b/hledger/.date.m4 @@ -1,2 +1,2 @@ m4_dnl Date to show in man pages. Updated by "Shake manuals" -m4_define({{_monthyear_}}, {{September 2023}})m4_dnl +m4_define({{_monthyear_}}, {{November 2023}})m4_dnl diff --git a/hledger/hledger.1 b/hledger/hledger.1 index 0333e9c05..49e7a1589 100644 --- a/hledger/hledger.1 +++ b/hledger/hledger.1 @@ -1,6 +1,6 @@ .\"t -.TH "HLEDGER" "1" "September 2023" "hledger-1.31.99 " "hledger User Manuals" +.TH "HLEDGER" "1" "November 2023" "hledger-1.31.99 " "hledger User Manuals" @@ -150,7 +150,7 @@ in any of the supported file formats, which currently are: .PP .TS tab(@); -lw(7.8n) lw(39.5n) lw(22.7n). +lw(12.3n) lw(30.0n) lw(27.7n). T{ Reader: T}@T{ @@ -664,17 +664,101 @@ or msys terminal, and vice versa. (See eg #961). .SS Regular expressions .PP -hledger uses regular expressions in a number of places: -.IP \[bu] 2 -query terms, on the command line and in the hledger-web search form: -\f[V]REGEX\f[R], \f[V]desc:REGEX\f[R], \f[V]cur:REGEX\f[R], -\f[V]tag:...=REGEX\f[R] -.IP \[bu] 2 -CSV rules conditional blocks: \f[V]if REGEX ...\f[R] -.IP \[bu] 2 -account alias directive and \f[V]--alias\f[R] option: -\f[V]alias /REGEX/ = REPLACEMENT\f[R], -\f[V]--alias /REGEX/=REPLACEMENT\f[R] +A regular expression (regexp) is a small piece of text where certain +characters (like \f[V].\f[R], \f[V]\[ha]\f[R], \f[V]$\f[R], \f[V]+\f[R], +\f[V]*\f[R], \f[V]()\f[R], \f[V]|\f[R], \f[V][]\f[R], \f[V]\[rs]\f[R]) +have special meanings, forming a tiny language for matching text +precisely - very useful in hledger and elsewhere. +To learn all about them, visit regular-expressions.info. +.PP +hledger supports regexps whenever you are entering a pattern to match +something, eg in query arguments, account aliases, CSV if rules, +hledger-web\[aq]s search form, hledger-ui\[aq]s \f[V]/\f[R] search, etc. +You may need to wrap them in quotes, especially at the command line (see +Special characters above). +Here are some examples: +.PP +Account name queries (quoted for command line use): +.IP +.nf +\f[C] +Regular expression: Matches: +------------------- ------------------------------------------------------------ +bank assets:bank, assets:bank:savings, expenses:art:banksy, ... +:bank assets:bank:savings, expenses:art:banksy +:bank: assets:bank:savings +\[aq]\[ha]bank\[aq] none of those ( \[ha] matches beginning of text ) +\[aq]bank$\[aq] assets:bank ( $ matches end of text ) +\[aq]big \[rs]$ bank\[aq] big $ bank ( \[rs] disables following character\[aq]s special meaning ) +\[aq]\[rs]bbank\[rs]b\[aq] assets:bank, assets:bank:savings ( \[rs]b matches word boundaries ) +\[aq](sav|check)ing\[aq] saving or checking ( (|) matches either alternative ) +\[aq]saving|checking\[aq] saving or checking ( outer parentheses are not needed ) +\[aq]savings?\[aq] saving or savings ( ? matches 0 or 1 of the preceding thing ) +\[aq]my +bank\[aq] my bank, my bank, ... ( + matches 1 or more of the preceding thing ) +\[aq]my *bank\[aq] mybank, my bank, my bank, ... ( * matches 0 or more of the preceding thing ) +\[aq]b.nk\[aq] bank, bonk, b nk, ... ( . matches any character ) +\f[R] +.fi +.PP +Some other queries: +.IP +.nf +\f[C] +desc:\[aq]amazon|amzn|audible\[aq] Amazon transactions +cur:EUR amounts with commodity symbol containing EUR +cur:\[aq]\[rs]$\[aq] amounts with commodity symbol containing $ +cur:\[aq]\[ha]\[rs]$$\[aq] only $ amounts, not eg AU$ or CA$ +cur:....? amounts with 4-or-more-character symbols +tag:.=202[1-3] things with any tag whose value contains 2021, 2022 or 2023 +\f[R] +.fi +.PP +Account name aliases: accept \f[V].\f[R] instead of \f[V]:\f[R] as +account separator: +.IP +.nf +\f[C] +alias /\[rs]./=: replaces all periods in account names with colons +\f[R] +.fi +.PP +Show multiple top-level accounts combined as one: +.IP +.nf +\f[C] +--alias=\[aq]/\[ha][\[ha]:]+/=combined\[aq] ( [\[ha]:] matches any character other than : ) +\f[R] +.fi +.PP +Show accounts with the second-level part removed: +.IP +.nf +\f[C] +--alias \[aq]/\[ha]([\[ha]:]+):[\[ha]:]+/ = \[rs]1\[aq] + match a top-level account and a second-level account + and replace those with just the top-level account + ( \[rs]1 in the replacement text means \[dq]whatever was matched + by the first parenthesised part of the regexp\[dq] +\f[R] +.fi +.PP +CSV rules: match CSV records containing dining-related MCC codes: +.IP +.nf +\f[C] +if \[rs]?MCC581[124] +\f[R] +.fi +.PP +Match CSV records with a specific amount around the end/start of month: +.IP +.nf +\f[C] +if %amount \[rs]b3\[rs].99 +& %date (29|30|31|01|02|03)$ +\f[R] +.fi +.SS hledger\[aq]s regular expressions .PP hledger\[aq]s regular expressions come from the regex-tdfa library. If they\[aq]re not doing what you expect, it\[aq]s important to know @@ -690,11 +774,11 @@ they are POSIX ERE (extended regular expressions) they also support GNU word boundaries (\f[V]\[rs]b\f[R], \f[V]\[rs]B\f[R], \f[V]\[rs]<\f[R], \f[V]\[rs]>\f[R]) .IP "5." 3 -they do not support backreferences; if you write \f[V]\[rs]1\f[R], it -will match the digit \f[V]1\f[R]. -Except when doing text replacement, eg in account aliases, where -backreferences can be used in the replacement string to reference -capturing groups in the search regexp. +backreferences are supported when doing text replacement in account +aliases or CSV rules, where backreferences can be used in the +replacement string to reference capturing groups in the search regexp. +Otherwise, if you write \f[V]\[rs]1\f[R], it will match the digit +\f[V]1\f[R]. .IP "6." 3 they do not support mode modifiers (\f[V](?s)\f[R]), character classes (\f[V]\[rs]w\f[R], \f[V]\[rs]d\f[R]), or anything else not mentioned @@ -765,7 +849,7 @@ T{ T}@T{ txt T}@T{ -csv +csv/tsv T}@T{ html T}@T{ @@ -1594,7 +1678,7 @@ A \f[I]decimal mark\f[R] can be written as a period or a comma: .nf \f[C] 1.23 -1,23456780000009 +1,23 \f[R] .fi .PP @@ -1611,27 +1695,17 @@ INR 9,99,99,999.00 \f[R] .fi .PP -Note, a number containing a single digit group mark and no decimal mark -is ambiguous. -Are these digit group marks or decimal marks ? -.IP -.nf -\f[C] -1,000 -1.000 -\f[R] -.fi +hledger is not biased towards period or comma decimal marks, so a number +containing just one period or comma, like \f[V]1,000\f[R] or +\f[V]1.000\f[R], is ambiguous. +In such cases hledger assumes it is a decimal mark, parsing both of +these as 1. .PP -If you don\[aq]t tell it otherwise, hledger will assume both of the -above are decimal marks, parsing both numbers as 1. -.PP -To prevent confusing parsing mistakes and undetected typos, especially -if your data contains digit group marks (eg, thousands separators), we -recommend explicitly declaring the decimal mark character in each -journal file, using a directive at the top of the file. -The \f[V]decimal-mark\f[R] directive is best, otherwise -\f[V]commodity\f[R] directives will also work. -These are described below. +To disambiguate these and ensure accurate number parsing, especially if +you use digit group marks, we recommend declaring the decimal mark. +You can declare it for each file with \f[V]decimal-mark\f[R] directives, +or for each commodity with \f[V]commodity\f[R] directives (described +below). .SS Commodity .PP Amounts in hledger have both a \[dq]quantity\[dq], which is a signed @@ -1680,74 +1754,50 @@ commodity 1 000 000.9455 .SS Commodity display style .PP For the amounts in each commodity, hledger chooses a consistent display -style to use in most reports. -(Exceptions: price amounts, and all amounts displayed by the -\f[V]print\f[R] command, are displayed with all of their decimal digits -visible.) +style (symbol placement, decimal mark and digit group marks, number of +decimal digits) to use in most reports. +This is inferred as follows: .PP -A commodity\[aq]s display style is inferred as follows. +First, if there\[aq]s a \f[V]D\f[R] directive declaring a default +commodity, that commodity symbol and amount format is applied to all +no-symbol amounts in the journal. .PP -First, if a default commodity is declared with \f[V]D\f[R], this -commodity and its style is applied to any no-symbol amounts in the -journal. +Then each commodity\[aq]s display style is determined from its +\f[V]commodity\f[R] directive. +We recommend always declaring commodities with \f[V]commodity\f[R] +directives, since they help ensure consistent display styles and +precisions, and bring other benefits such as error checking for +commodity symbols. .PP -Then each commodity\[aq]s style is inferred from one of the following, -in order of preference: +But if a \f[V]commodity\f[R] directive is not present, hledger infers a +commodity\[aq]s display styles from its amounts as they are written in +the journal (excluding cost amounts and amounts in periodic transaction +rules or auto posting rules). +It uses .IP \[bu] 2 -The commodity directive for that commodity (including the no-symbol -commodity), if any. +the symbol placement and decimal mark of the first amount seen .IP \[bu] 2 -The amounts in that commodity seen in the journal\[aq]s transactions. -(Posting amounts only; prices and periodic or auto rules are ignored, -currently.) +the digit group marks of the first amount with digit group marks .IP \[bu] 2 -The built-in fallback style, which looks like this: \f[V]$1000.00\f[R]. -(Symbol on the left, period decimal mark, two decimal places.) +and the maximum number of decimal digits seen across all amounts. .PP -A style is inferred from journal amounts as follows: -.IP \[bu] 2 -Use the general style (decimal mark, symbol placement) of the first -amount -.IP \[bu] 2 -Use the first-seen digit group style (digit group mark, digit group -sizes), if any -.IP \[bu] 2 -Use the maximum number of decimal places of all. +And as fallback if no applicable amounts are found, it would use a +default style, like \f[V]$1000.00\f[R] (symbol on the left with no +space, period as decimal mark, and two decimal digits). .PP -Cost amounts don\[aq]t affect the commodity display style directly, but -occasionally they can do so indirectly (eg when a posting\[aq]s amount -is inferred using a cost). -If you find this causing problems, use a commodity directive to fix the -display style. -.PP -To summarise: each commodity\[aq]s amounts will be normalised to (a) the -style declared by a \f[V]commodity\f[R] directive, or (b) the style of -the first posting amount in the journal, with the first-seen digit group -style and the maximum-seen number of decimal places. -So if your reports are showing amounts in a way you don\[aq]t like, eg -with too many decimal places, use a commodity directive. -Some examples: -.IP -.nf -\f[C] -# declare euro, dollar, bitcoin and no-symbol commodities and set their -# input number formats and output display styles: -commodity EUR 1.000, -commodity $1000.00 -commodity 1000.00000000 BTC -commodity 1 000. -\f[R] -.fi -.PP -The inferred commodity style can be overridden by supplying a command -line option. +Finally, commodity styles can be overridden by the +\f[V]-c/--commodity-style\f[R] command line option. .SS Rounding .PP Amounts are stored internally as decimal numbers with up to 255 decimal -places, and displayed with the number of decimal places specified by the -commodity display style. -Note, hledger uses banker\[aq]s rounding: it rounds to the nearest even -number, eg 0.5 displayed with zero decimal places is \[dq]0\[dq]). +places. +They are displayed with their original journal precisions by print and +print-like reports, and rounded to their display precision (the number +of decimal digits specified by the commodity display style) by other +reports. +When rounding, hledger uses banker\[aq]s rounding (it rounds to the +nearest even digit). +So eg 0.5 displayed with zero decimal digits appears as \[dq]0\[dq]. .PP .SS Costs .PP @@ -2946,104 +2996,101 @@ $ hledger accounts --alias assets=bassetts type:a .fi .SS \f[V]commodity\f[R] directive .PP -You can use \f[V]commodity\f[R] directives to declare your commodities. -In fact the \f[V]commodity\f[R] directive performs several functions at -once: +The \f[V]commodity\f[R] directive performs several functions: .IP "1." 3 -It declares commodities which may be used in the journal. -This can optionally be enforced, providing useful error checking. -(Cf Commodity error checking) +It declares which commodity symbols may be used in the journal, enabling +useful error checking with strict mode or the check command. +(See Commodity error checking below.) .IP "2." 3 -It declares which decimal mark character (period or comma), to expect -when parsing input - useful to disambiguate international number formats -in your data. -Without this, hledger will parse both \f[V]1,000\f[R] and -\f[V]1.000\f[R] as 1. -(Cf Amounts) +It declares the precision with which this commodity\[aq]s amounts should +be compared when checking for balanced transactions. .IP "3." 3 -It declares how to render the commodity\[aq]s amounts when displaying -output - the decimal mark, any digit group marks, the number of decimal -places, symbol placement and so on. -(Cf Commodity display style) +It declares how this commodity\[aq]s amounts should be displayed, eg +their symbol placement, digit group mark if any, digit group sizes, +decimal mark (period or comma), and the number of decimal places. +(See Commodity display style above.) +.IP "4." 3 +It sets which decimal mark (period or comma) to expect when parsing +subsequent amounts in this commodity (if there is no +\f[V]decimal-mark\f[R] directive in effect. +See Decimal marks, digit group marks above. +For related dev discussion, see #793.) .PP -You will run into one of the problems solved by commodity directives -sooner or later, so we recommend using them, for robust and predictable -parsing and display. +Declaring commodities solves several common parsing/display problems, so +we recommend it. +Generally you should put \f[V]commodity\f[R] directives at the top of +your journal file (because function 4 is position-sensitive). +.SS Commodity directive syntax .PP -Generally you should put them at the top of your journal file (since for -function 2, they affect only following amounts, cf #793). -.PP -A commodity directive is just the word \f[V]commodity\f[R] followed by a -sample amount, like this: +A commodity directive is normally the word \f[V]commodity\f[R] followed +by a sample amount (and optionally a comment). +Only the amount\[aq]s symbol and format is significant. +Eg: .IP .nf \f[C] -;commodity SAMPLEAMOUNT - commodity $1000.00 -commodity 1,000.0000 AAAA ; optional same-line comment +commodity 1.000,00 EUR +commodity 1 000 000.0000 ; the no-symbol commodity \f[R] .fi .PP -It may also be written on multiple lines, and use the \f[V]format\f[R] -subdirective, as in Ledger. -Note in this case the commodity symbol appears twice; it must be the -same in both places: +A commodity directive\[aq]s sample amount must always include a period +or comma decimal mark (this rule helps disambiguate decimal marks and +digit group marks). +If you don\[aq]t want to show any decimal digits, write the decimal mark +at the end: +.IP +.nf +\f[C] +commodity 1000. AAAA ; show AAAA with no decimals +\f[R] +.fi +.PP +Commodity symbols containing spaces, numbers, or punctuation must be +enclosed in double quotes, as usual: +.IP +.nf +\f[C] +commodity 1.0000 \[dq]AAAA 2023\[dq] +\f[R] +.fi +.PP +Commodity directives normally include a sample amount, but can declare +only a symbol (ie, just function 1 above): +.IP +.nf +\f[C] +commodity $ +commodity INR +commodity \[dq]AAAA 2023\[dq] +commodity \[dq]\[dq] ; the no-symbol commodity +\f[R] +.fi +.PP +Commodity directives may also be written with an indented +\f[V]format\f[R] subdirective, as in Ledger. +The symbol is repeated and must be the same in both places. +Other subdirectives are currently ignored: .IP .nf \f[C] -;commodity SYMBOL -; format SAMPLEAMOUNT - ; display indian rupees with currency name on the left, ; thousands, lakhs and crores comma-separated, ; period as decimal point, and two decimal places. commodity INR format INR 1,00,00,000.00 + an unsupported subdirective ; ignored by hledger \f[R] .fi -.PP -Other indented subdirectives are currently ignored. -.PP -Remember that if the commodity symbol contains spaces, numbers, or -punctuation, it must be enclosed in double quotes (cf Commodity). -.PP -The amount\[aq]s quantity does not matter; only the format is -significant. -It must include a decimal mark - either a period or a comma - followed -by 0 or more decimal digits. -.PP -A few more examples: -.IP -.nf -\f[C] -# number formats for $, EUR, INR and the no-symbol commodity: -commodity $1,000.00 -commodity EUR 1.000,00 -commodity INR 9,99,99,999.0 -commodity 1 000 000. -\f[R] -.fi -.PP -Note hledger normally uses banker\[aq]s rounding, so 0.5 displayed with -zero decimal digits is \[dq]0\[dq]. -(More at Commodity display style.) -.PP -Even in the presence of commodity directives, the commodity display -style can still be overridden by supplying a command line option. .SS Commodity error checking .PP -In strict mode, enabled with the \f[V]-s\f[R]/\f[V]--strict\f[R] flag, -hledger will report an error if a commodity symbol is used that has not -been declared by a \f[V]commodity\f[R] directive. -This works similarly to account error checking, see the notes there for -more details. -.PP -Note, this disallows amounts without a commodity symbol, because -currently it\[aq]s not possible (?) -to declare the \[dq]no-symbol\[dq] commodity with a directive. -This is one exception for convenience: zero amounts are always allowed -to have no commodity symbol. +In strict mode (\f[V]-s\f[R]/\f[V]--strict\f[R]) (or when you run +\f[V]hledger check commodities\f[R]), hledger will report an error if an +undeclared commodity symbol is used. +(With one exception: zero amounts are always allowed to have no +commodity symbol.) +It works like account error checking (described above). .SS \f[V]decimal-mark\f[R] directive .PP You can use a \f[V]decimal-mark\f[R] directive - usually one per file, @@ -4215,9 +4262,10 @@ They can be used instead of or in addition to a fields list (see above). To assign a value to a hledger field, write the field name (any of the standard hledger field/pseudo-field names, defined below), a space, followed by a text value on the same line. -This text value may interpolate CSV fields, referenced by their 1-based -position in the CSV record (\f[V]%N\f[R]), or by the name they were -given in the fields list (\f[V]%CSVFIELD\f[R]). +This text value may interpolate CSV fields, referenced either by their +1-based position in the CSV record (\f[V]%N\f[R]) or by the name they +were given in the fields list (\f[V]%CSVFIELD\f[R]), and regular +expression match groups (\f[V]\[rs]N\f[R]). .PP Some examples: .IP @@ -4540,7 +4588,39 @@ By default they are OR\[aq]d (any one of them can match) When a matcher is preceded by ampersand (\f[V]&\f[R]) it will be AND\[aq]ed with the previous matcher (both of them must match). .PP -There\[aq]s not yet an easy syntax to negate a matcher. +When a matcher is preceded by an exclamation mark (!), the matcher will +be negated, ie it will exclude CSV records that match. +.SS Match groups +.PP +Matchers can define match groups: parenthesised portions of the regular +expression which are available for reference in field assignments. +Groups are enclosed in regular parentheses (\f[V](\f[R] and \f[V])\f[R]) +and can be nested. +Each group is available in field assignments using the token +\f[V]\[rs]N\f[R], where N is an index into the match groups for this +conditional block (e.g. +\f[V]\[rs]1\f[R], \f[V]\[rs]2\f[R], etc.). +.PP +Example: Warp credit card payment postings to the beginning of the +billing period (Month start), to match how they are presented in +statements, using posting dates: +.IP +.nf +\f[C] +if %date (....-..)-.. + comment2 date:\[rs]1-01 +\f[R] +.fi +.PP +Another example: Read the expense account from the CSV field, but throw +away a prefix: +.IP +.nf +\f[C] +if %account1 liabilities:family:(expenses:.*) + account1 \[rs]1 +\f[R] +.fi .SS \f[V]if\f[R] table .PP \[dq]if tables\[dq] are an alternative to if blocks; they can express @@ -4557,20 +4637,24 @@ MATCHERC,VALUE1,VALUE2,... \f[R] .fi .PP -The first character after \f[V]if\f[R] is taken to be the separator for -the rest of the table. +The first character after \f[V]if\f[R] is taken to be this if +table\[aq]s field separator. +It is unrelated to the separator used in the CSV file. It should be a non-alphanumeric character like \f[V],\f[R] or -\f[V]|\f[R] that does not appear anywhere else in the table. -(Note: it is unrelated to the CSV file\[aq]s separator.) -Whitespace can be used in the matcher lines for readability, but not in -the if line currently. -The table must be terminated by an empty line (or end of file). +\f[V]|\f[R] that does not appear anywhere else in the table (it should +not be used in field names or matchers or values, and it cannot be +escaped with a backslash). +.PP Each line must contain the same number of separators; empty values are allowed. +Whitespace can be used in the matcher lines for readability (but not in +the if line, currently). +The table must be terminated by an empty line (or end of file). .PP -The above means: try all of the matchers; whenever a matcher succeeds, -assign all of the values on that line to the corresponding hledger -fields; later lines can overrider earlier ones. +An if table like the above is interpreted as follows: try all of the +matchers; whenever a matcher succeeds, assign all of the values on that +line to the corresponding hledger fields; later lines can overrider +earlier ones. It is equivalent to this sequence of if blocks: .IP .nf @@ -5757,6 +5841,59 @@ $ hledger -f a.timedot --alias /\[rs]\[rs]./=: bal --tree .PP A sample.timedot file. .SH PART 3: REPORTING CONCEPTS +.SH Amount formatting, parseability +.PP +If you\[aq]re wondering why your \f[V]print\f[R] report sometimes shows +trailing decimal marks, even when there are no decimal digits; it does +this to disambiguate ambiguous amounts (amounts which have one digit +group mark and no decimal digits), allowing them to be re-parsed +reliably. +.PP +More generally: hledger output falls into three rough categories, which +format amounts a little bit differently to suit different consumers: +.PP +\f[B]1. +\[dq]hledger-readable output\[dq] - should be readable by hledger (and +by humans)\f[R] +.IP \[bu] 2 +This is produced by reports that show full journal entries: +\f[V]print\f[R], \f[V]import\f[R], \f[V]close\f[R], \f[V]rewrite\f[R] +etc. +.IP \[bu] 2 +It shows amounts with their original journal precisions, which may not +be consistent. +.IP \[bu] 2 +It adds a trailing decimal mark when needed to avoid showing ambiguous +amounts. +.IP \[bu] 2 +It can be parsed reliably (by hledger and ledger2beancount at least, but +perhaps not by Ledger..) +.PP +\f[B]2. +\[dq]human-readable output\[dq] - usually for humans\f[R] +.IP \[bu] 2 +This is produced by all other reports. +.IP \[bu] 2 +It shows amounts with standard display precisions, which will be +consistent within each commodity. +.IP \[bu] 2 +It shows ambiguous amounts unmodified. +.IP \[bu] 2 +It can be parsed reliably in the context of a known report (when you +know decimals are consistently not being shown, you can assume a single +mark is a digit group mark). +.PP +\f[B]3. +\[dq]machine-readable output\[dq] - usually for other software\f[R] +.IP \[bu] 2 +This is produced by all reports when an output format like +\f[V]csv\f[R], \f[V]tsv\f[R], \f[V]json\f[R], or \f[V]sql\f[R] is +selected. +.IP \[bu] 2 +It shows amounts as 1 or 2 do, but without digit group marks. +.IP \[bu] 2 +It can be parsed reliably (if needed, the decimal mark can be changed +with -c/--commodity-style). .SH Time periods .PP .SS Report start & end date @@ -7212,21 +7349,33 @@ tell it which currency you want to convert to, and it tries to convert everything to that. .SS Valuation date .PP -Since market prices can change from day to day, market value reports -have a valuation date (or more than one), which determines which market -prices will be used. +Market prices can change from day to day. +hledger will use the prices on a particular valuation date (or on more +than one date). +By default hledger uses \[dq]end\[dq] dates for valuation. +More specifically: +.IP \[bu] 2 +For single period reports (including normal print and register reports): +.RS 2 +.IP \[bu] 2 +If an explicit report end date is specified, that is used +.IP \[bu] 2 +Otherwise the latest transaction date or P directive date is used (even +if it\[aq]s in the future) +.RE +.IP \[bu] 2 +For multiperiod reports, each period is valued on its last day. .PP -For single period reports, if an explicit report end date is specified, -that will be used as the valuation date; otherwise the valuation date is -the journal\[aq]s end date. -.PP -For multiperiod reports, each column/period is valued on the last day of -the period, by default. +This can be customised with the --value option described below, which +can select either \[dq]then\[dq], \[dq]end\[dq], \[dq]now\[dq], or +\[dq]custom\[dq] dates. +(Note, this has a bug in hledger-ui <=1.31: turning on valuation with +the \f[V]V\f[R] key always resets it to \[dq]end\[dq].) .SS Finding market price .PP To convert a commodity A to its market value in another commodity B, hledger looks for a suitable market price (exchange rate) as follows, in -this order of preference : +this order of preference: .IP "1." 3 A \f[I]declared market price\f[R] or \f[I]inferred market price\f[R]: A\[aq]s latest market price in B on or before the valuation date as @@ -7574,56 +7723,6 @@ $ hledger -f- print --value=2000-01-15 (a) 1 B \f[R] .fi -.PP -You may need to explicitly set a commodity\[aq]s display style, when -reverse prices are used. -Eg this output might be surprising: -.IP -.nf -\f[C] -P 2000-01-01 A 2B - -2000-01-01 - a 1B - b -\f[R] -.fi -.IP -.nf -\f[C] -$ hledger print -x -X A -2000-01-01 - a 0 - b 0 -\f[R] -.fi -.PP -Explanation: because there\[aq]s no amount or commodity directive -specifying a display style for A, 0.5A gets the default style, which -shows no decimal digits. -Because the displayed amount looks like zero, the commodity symbol and -minus sign are not displayed either. -Adding a commodity directive sets a more useful display style for A: -.IP -.nf -\f[C] -P 2000-01-01 A 2B -commodity 0.00A - -2000-01-01 - a 1B - b -\f[R] -.fi -.IP -.nf -\f[C] -$ hledger print -X A -2000-01-01 - a 0.50A - b -0.50A -\f[R] -.fi .SS Interaction of valuation and queries .PP When matching postings based on queries in the presence of valuation, @@ -8324,21 +8423,25 @@ memory, use the \f[V]--align-all\f[R] flag. .PP This command also supports the output destination and output format options. -The output formats supported are \f[V]txt\f[R], \f[V]csv\f[R], and -\f[V]json\f[R]. -.SS aregister and custom posting dates +The output formats supported are \f[V]txt\f[R], \f[V]csv\f[R], +\f[V]tsv\f[R], and \f[V]json\f[R]. +.SS aregister and posting dates .PP -Transactions whose date is outside the report period can still be shown, -if they have a posting to this account dated inside the report period. -(And in this case it\[aq]s the posting date that is shown.) -This ensures that \f[V]aregister\f[R] can show an accurate historical -running balance, matching the one shown by \f[V]register -H\f[R] with -the same arguments. +aregister always shows one line (and date and amount) per transaction. +But sometimes transactions have postings with different dates. +Also, not all of a transaction\[aq]s postings may be within the report +period. +To resolve this, aregister shows the earliest of the transaction\[aq]s +date and posting dates that is in-period, and the sum of the in-period +postings. +In other words it will show a combined line item with just the earliest +date, and the running balance will (temporarily, until the +transaction\[aq]s last posting) be inaccurate. +Use \f[V]register -H\f[R] if you need to see the individual postings. .PP -To filter strictly by transaction date instead, add the -\f[V]--txn-dates\f[R] flag. -If you use this flag and some of your postings have custom dates, -it\[aq]s probably best to assume the running balance is wrong. +There is also a \f[V]--txn-dates\f[R] flag, which filters strictly by +transaction date, ignoring posting dates. +This too can cause an inaccurate running balance. .SS balance .PP (bal) @@ -8427,8 +8530,8 @@ commodities displayed on the same line or multiple lines (\f[V]--layout\f[R]) .PP This command supports the output destination and output format options, -with output formats \f[V]txt\f[R], \f[V]csv\f[R], \f[V]json\f[R], and -(multi-period reports only:) \f[V]html\f[R]. +with output formats \f[V]txt\f[R], \f[V]csv\f[R], \f[V]tsv\f[R], +\f[V]json\f[R], and (multi-period reports only:) \f[V]html\f[R]. In \f[V]txt\f[R] output in a colour-supporting terminal, negative amounts are shown in red. .PP @@ -9718,7 +9821,7 @@ sign flipped. .PP This command also supports the output destination and output format options The output formats supported are \f[V]txt\f[R], \f[V]csv\f[R], -\f[V]html\f[R], and (experimental) \f[V]json\f[R]. +\f[V]tsv\f[R], \f[V]html\f[R], and (experimental) \f[V]json\f[R]. .SS balancesheetequity .PP (bse) @@ -9774,7 +9877,7 @@ with their sign flipped. .PP This command also supports the output destination and output format options The output formats supported are \f[V]txt\f[R], \f[V]csv\f[R], -\f[V]html\f[R], and (experimental) \f[V]json\f[R]. +\f[V]tsv\f[R], \f[V]html\f[R], and (experimental) \f[V]json\f[R]. .SS cashflow .PP (cf) @@ -9831,7 +9934,7 @@ but with smarter account detection. .PP This command also supports the output destination and output format options The output formats supported are \f[V]txt\f[R], \f[V]csv\f[R], -\f[V]html\f[R], and (experimental) \f[V]json\f[R]. +\f[V]tsv\f[R], \f[V]html\f[R], and (experimental) \f[V]json\f[R]. .SS check .PP Check for various kinds of errors in your data. @@ -10356,11 +10459,11 @@ $ hledger help -m journal # show it with man, even if info is installed .fi .SS import .PP -Read new transactions added to each FILE since last run, and add them to -the journal. +Read new transactions added to each FILE provided as arguments since +last run, and add them to the journal. Or with --dry-run, just print the transactions that would be added. -Or with --catchup, just mark all of the FILEs\[aq] transactions as -imported, without actually importing any. +Or with --catchup, just mark all of the FILEs\[aq] current transactions +as imported, without importing them. .PP This command may append new transactions to the main journal file (which should be in journal format). @@ -10380,16 +10483,16 @@ Note you can import from any file format, though CSV files are the most common import source, and these docs focus on that case. .SS Deduplication .PP -As a convenience \f[V]import\f[R] does \f[I]deduplication\f[R] while -reading transactions. -This does not mean \[dq]ignore transactions that look the same\[dq], but -rather \[dq]ignore transactions that have been seen before\[dq]. -This is intended for when you are periodically importing foreign data -which may contain already-imported transactions. -So eg, if every day you download bank CSV files containing redundant -data, you can safely run \f[V]hledger import bank.csv\f[R] and only new -transactions will be imported. -(\f[V]import\f[R] is idempotent.) +\f[V]import\f[R] does \f[I]time-based deduplication\f[R], to detect only +the new transactions since the last successful import. +(This does not mean \[dq]ignore transactions that look the same\[dq], +but rather \[dq]ignore transactions that have been seen before\[dq].) +This is intended for when you are periodically importing downloaded +data, which may overlap with previous downloads. +Eg if every week (or every day) you download a bank\[aq]s last three +months of CSV data, you can safely run +\f[V]hledger import thebank.csv\f[R] each time and only new transactions +will be imported. .PP Since the items being read (CSV records, eg) often do not come with unique identifiers, hledger detects new transactions by date, assuming @@ -10409,7 +10512,9 @@ won\[aq]t matter (and if you import often, the new transactions will be few, so less likely to be the ones affected). .PP hledger remembers the latest date processed in each input file by saving -a hidden \[dq].latest\[dq] state file in the same directory. +a hidden \[dq].latest.FILE\[dq] file in FILE\[aq]s directory (after a +succesful import). +.PP Eg when reading \f[V]finance/bank.csv\f[R], it will look for and update the \f[V]finance/.latest.bank.csv\f[R] state file. The format is simple: one or more lines containing the same ISO-format @@ -10529,7 +10634,7 @@ flipped. .PP This command also supports the output destination and output format options The output formats supported are \f[V]txt\f[R], \f[V]csv\f[R], -\f[V]html\f[R], and (experimental) \f[V]json\f[R]. +\f[V]tsv\f[R], \f[V]html\f[R], and (experimental) \f[V]json\f[R]. .SS notes .PP List the unique notes that appear in transactions. @@ -10575,13 +10680,22 @@ Person A .fi .SS prices .PP -Print market price directives from the journal. -With --infer-market-prices, generate additional market prices from -costs. -With --infer-reverse-prices, also generate market prices by inverting +Print the market prices declared with P directives. +With --infer-market-prices, also show any additional prices inferred +from costs. +With --show-reverse, also show additional prices inferred by reversing known prices. -Prices can be filtered by a query. -Price amounts are displayed with their full precision. +.PP +Price amounts are always displayed with their full precision, except for +reverse prices which are limited to 8 decimal digits. +.PP +Prices can be filtered by a date:, cur: or amt: query. +.PP +Generally if you run this command with --infer-market-prices +--show-reverse, it will show the same prices used internally to +calculate value reports. +But if in doubt, you can inspect those directly by running the value +report with --debug=2. .SS print .PP Show transaction journal entries, sorted by date. @@ -10590,28 +10704,16 @@ The print command displays full journal entries (transactions) from the journal file, sorted by date (or with \f[V]--date2\f[R], by secondary date). .PP -Amounts are shown mostly normalised to commodity display style, eg the -placement of commodity symbols will be consistent. -All of their decimal places are shown, as in the original journal entry -(with one alteration: in some cases trailing zeroes are added.) -.PP -Amounts are shown right-aligned within each transaction (but not across -all transactions). -.PP Directives and inter-transaction comments are not shown, currently. This means the print command is somewhat lossy, and if you are using it -to reformat your journal you should take care to also copy over the -directives and file-level comments. +to reformat/regenerate your journal you should take care to also copy +over the directives and inter-transaction comments. .PP Eg: .IP .nf \f[C] -$ hledger print -2008/01/01 income - assets:bank:checking $1 - income:salary $-1 - +$ hledger print -f examples/sample.journal date:200806 2008/06/01 gift assets:bank:checking $1 income:gifts $-1 @@ -10624,16 +10726,63 @@ $ hledger print expenses:food $1 expenses:supplies $1 assets:cash $-2 - -2008/12/31 * pay off - liabilities:debts $1 - assets:bank:checking $-1 \f[R] .fi +.SS print explicitness +.PP +Normally, whether posting amounts are implicit or explicit is preserved. +For example, when an amount is omitted in the journal, it will not +appear in the output. +Similarly, if a conversion cost is implied but not written, it will not +appear in the output. +.PP +You can use the \f[V]-x\f[R]/\f[V]--explicit\f[R] flag to force explicit +display of all amounts and costs. +This can be useful for troubleshooting or for making your journal more +readable and robust against data entry errors. +\f[V]-x\f[R] is also implied by using any of +\f[V]-B\f[R],\f[V]-V\f[R],\f[V]-X\f[R],\f[V]--value\f[R]. +.PP +The \f[V]-x\f[R]/\f[V]--explicit\f[R] flag will cause any postings with +a multi-commodity amount (which can arise when a multi-commodity +transaction has an implicit amount) to be split into multiple +single-commodity postings, keeping the output parseable. +.SS print amount style +.PP +Amounts are shown right-aligned within each transaction (but not aligned +across all transactions; you can do that with ledger-mode in Emacs). +.PP +Amounts will be (mostly) normalised to their commodity display style: +their symbol placement, decimal mark, and digit group marks will be made +consistent. +By default, decimal digits are shown as they are written in the journal. +.PP +With the \f[V]--round\f[R] option, \f[V]print\f[R] will try increasingly +hard to display decimal digits according to the commodity display +styles: +.IP \[bu] 2 +\f[V]--round=none\f[R] show amounts with original precisions (default) +.IP \[bu] 2 +\f[V]--round=soft\f[R] add/remove decimal zeros in amounts (except +costs) +.IP \[bu] 2 +\f[V]--round=hard\f[R] round amounts (except costs), possibly hiding +significant digits +.IP \[bu] 2 +\f[V]--round=all\f[R] round all amounts and costs +.PP +\f[V]soft\f[R] is good for non-lossy cleanup, formatting amounts more +consistently where it\[aq]s safe to do so. +.PP +\f[V]hard\f[R] and \f[V]all\f[R] can cause \f[V]print\f[R] to show +invalid unbalanced journal entries; they may be useful eg for stronger +cleanup, with manual fixups when needed. +.SS print parseability .PP print\[aq]s output is usually a valid hledger journal, and you can process it again with a second hledger command. -This can be useful for certain kinds of search, eg: +This can be useful for certain kinds of search (though the same can be +achieved with \f[V]expr:\f[R] queries now): .IP .nf \f[C] @@ -10652,43 +10801,47 @@ balance assignment amounts, potentially causing those to fail. Auto postings can generate postings with too many missing amounts. .IP \[bu] 2 Account aliases can generate bad account names. +.SS print, other features .PP -Normally, the journal entry\[aq]s explicit or implicit amount style is -preserved. -For example, when an amount is omitted in the journal, it will not -appear in the output. -Similarly, when a cost is implied but not written, it will not appear in -the output. -You can use the \f[V]-x\f[R]/\f[V]--explicit\f[R] flag to make all -amounts and costs explicit, which can be useful for troubleshooting or -for making your journal more readable and robust against data entry -errors. -\f[V]-x\f[R] is also implied by using any of -\f[V]-B\f[R],\f[V]-V\f[R],\f[V]-X\f[R],\f[V]--value\f[R]. +With \f[V]-B\f[R]/\f[V]--cost\f[R], amounts with costs are shown +converted to cost. .PP -Note, \f[V]-x\f[R]/\f[V]--explicit\f[R] will cause postings with a -multi-commodity amount (these can arise when a multi-commodity -transaction has an implicit amount) to be split into multiple -single-commodity postings, keeping the output parseable. -.PP -With \f[V]-B\f[R]/\f[V]--cost\f[R], amounts with costs are converted to -cost using that price. -This can be used for troubleshooting. -.PP -With \f[V]-m DESC\f[R]/\f[V]--match=DESC\f[R], print does a fuzzy search -for one recent transaction whose description is most similar to DESC. -DESC should contain at least two characters. -If there is no similar-enough match, no transaction will be shown and -the program exit code will be non-zero. -.PP -With \f[V]--new\f[R], hledger prints only transactions it has not seen -on a previous run. +With \f[V]--new\f[R], print shows only transactions it has not seen on a +previous run. This uses the same deduplication system as the \f[V]import\f[R] command. (See import\[aq]s docs for details.) .PP +With \f[V]-m DESC\f[R]/\f[V]--match=DESC\f[R], print shows one recent +transaction whose description is most similar to DESC. +DESC should contain at least two characters. +If there is no similar-enough match, no transaction will be shown and +the program exit code will be non-zero. +.SS print output format +.PP This command also supports the output destination and output format -options The output formats supported are \f[V]txt\f[R], \f[V]csv\f[R], -and (experimental) \f[V]json\f[R] and \f[V]sql\f[R]. +options The output formats supported are \f[V]txt\f[R], +\f[V]beancount\f[R], \f[V]csv\f[R], \f[V]tsv\f[R], \f[V]json\f[R] and +\f[V]sql\f[R]. +.PP +\f[I]Experimental:\f[R] The \f[V]beancount\f[R] format tries to produce +Beancount-compatible output. +It is very basic and may require additional manual fixups: +.IP \[bu] 2 +Transaction and postings with unmarked status are converted to cleared +(\[ga]*\[ga]\[ga]) status. +.IP \[bu] 2 +Transactions\[aq] payee and or note are wrapped in double quotes. +.IP \[bu] 2 +Transaction tags are copied to Beancount #tag format. +.IP \[bu] 2 +Account name parts are capitalised, and if the first account name part +is not one of Assets, Liabilities, Equity, Income, or Expenses, +\[dq]Equity:\[dq] is prepended. +.IP \[bu] 2 +The \f[V]$\f[R] commodity symbol is converted to \f[V]USD\f[R]. +.IP \[bu] 2 +An \f[V]open\f[R] directive is generated for each account used, on the +earliest transaction date. .PP Here\[aq]s an example of print\[aq]s CSV output: .IP @@ -10893,7 +11046,7 @@ $ hledger reg -w $COLUMNS,40 # use terminal width, & description width 40 .PP This command also supports the output destination and output format options The output formats supported are \f[V]txt\f[R], \f[V]csv\f[R], -and (experimental) \f[V]json\f[R]. +\f[V]tsv\f[R], and (experimental) \f[V]json\f[R]. .SS rewrite .PP Print all transactions, rewriting the postings of matched transactions. @@ -11464,7 +11617,7 @@ many people; adapt as needed: .IP .nf \f[C] -$ echo \[aq]export LEDGER_FILE=\[ti]/finance/2023.journal\[ga] >> \[ti]/.profile +$ echo \[aq]export LEDGER_FILE=\[ti]/finance/2023.journal\[aq] >> \[ti]/.profile $ source \[ti]/.profile \f[R] .fi @@ -11956,6 +12109,16 @@ $ echo \[dq]export LANG=en_US.utf8\[dq] >>\[ti]/.profile \f[R] .fi .PP +If you are using Nix (not NixOS) for GHC and Hledger, you might need to +set the \f[V]LOCALE_ARCHIVE\f[R] variable: +.IP +.nf +\f[C] +$ echo \[dq]export LOCALE_ARCHIVE=${glibcLocales}/lib/locale/locale-archive\[dq] >>\[ti]/.profile +# close and re-open terminal window +\f[R] +.fi +.PP \f[B]COMPATIBILITY ISSUES: hledger gives an error with my Ledger file\f[R] .PD 0 diff --git a/hledger/hledger.info b/hledger/hledger.info index a620ee92d..7a010c7f4 100644 --- a/hledger/hledger.info +++ b/hledger/hledger.info @@ -93,6 +93,7 @@ file" and "Setting opening balances" sections in PART 5: COMMON TASKS. * Timeclock:: * Timedot:: * PART 3 REPORTING CONCEPTS:: +* Amount formatting parseability:: * Time periods:: * Depth:: * Queries:: @@ -154,19 +155,18 @@ File: hledger.info, Node: Data formats, Next: Standard input, Up: Input Usually the data file is in hledger's journal format, but it can be in any of the supported file formats, which currently are: -Reader: Reads: Used for file - extensions: --------------------------------------------------------------------------- -'journal'hledger journal files and some Ledger '.journal' '.j' - journals, for transactions '.hledger' '.ledger' -'timeclock'timeclock files, for precise time '.timeclock' - logging -'timedot'timedot files, for approximate time '.timedot' - logging -'csv' CSV/SSV/TSV/character-separated '.csv' '.ssv' '.tsv' - values, for data import '.csv.rules' - '.ssv.rules' - '.tsv.rules' +Reader: Reads: Used for file extensions: +---------------------------------------------------------------------------- +'journal' hledger journal files and '.journal' '.j' '.hledger' + some Ledger journals, for '.ledger' + transactions +'timeclock' timeclock files, for precise '.timeclock' + time logging +'timedot' timedot files, for '.timedot' + approximate time logging +'csv' CSV/SSV/TSV/character-separated '.csv' '.ssv' '.tsv' + values, for data import '.csv.rules' '.ssv.rules' + '.tsv.rules' These formats are described in more detail below. @@ -667,15 +667,82 @@ File: hledger.info, Node: Regular expressions, Next: Argument files, Prev: Un 5.4 Regular expressions ======================= -hledger uses regular expressions in a number of places: +A regular expression (regexp) is a small piece of text where certain +characters (like '.', '^', '$', '+', '*', '()', '|', '[]', '\') have +special meanings, forming a tiny language for matching text precisely - +very useful in hledger and elsewhere. To learn all about them, visit +regular-expressions.info. - * query terms, on the command line and in the hledger-web search - form: 'REGEX', 'desc:REGEX', 'cur:REGEX', 'tag:...=REGEX' - * CSV rules conditional blocks: 'if REGEX ...' - * account alias directive and '--alias' option: 'alias /REGEX/ = - REPLACEMENT', '--alias /REGEX/=REPLACEMENT' + hledger supports regexps whenever you are entering a pattern to match +something, eg in query arguments, account aliases, CSV if rules, +hledger-web's search form, hledger-ui's '/' search, etc. You may need +to wrap them in quotes, especially at the command line (see Special +characters above). Here are some examples: - hledger's regular expressions come from the regex-tdfa library. If + Account name queries (quoted for command line use): + +Regular expression: Matches: +------------------- ------------------------------------------------------------ +bank assets:bank, assets:bank:savings, expenses:art:banksy, ... +:bank assets:bank:savings, expenses:art:banksy +:bank: assets:bank:savings +'^bank' none of those ( ^ matches beginning of text ) +'bank$' assets:bank ( $ matches end of text ) +'big \$ bank' big $ bank ( \ disables following character's special meaning ) +'\bbank\b' assets:bank, assets:bank:savings ( \b matches word boundaries ) +'(sav|check)ing' saving or checking ( (|) matches either alternative ) +'saving|checking' saving or checking ( outer parentheses are not needed ) +'savings?' saving or savings ( ? matches 0 or 1 of the preceding thing ) +'my +bank' my bank, my bank, ... ( + matches 1 or more of the preceding thing ) +'my *bank' mybank, my bank, my bank, ... ( * matches 0 or more of the preceding thing ) +'b.nk' bank, bonk, b nk, ... ( . matches any character ) + + Some other queries: + +desc:'amazon|amzn|audible' Amazon transactions +cur:EUR amounts with commodity symbol containing EUR +cur:'\$' amounts with commodity symbol containing $ +cur:'^\$$' only $ amounts, not eg AU$ or CA$ +cur:....? amounts with 4-or-more-character symbols +tag:.=202[1-3] things with any tag whose value contains 2021, 2022 or 2023 + + Account name aliases: accept '.' instead of ':' as account separator: + +alias /\./=: replaces all periods in account names with colons + + Show multiple top-level accounts combined as one: + +--alias='/^[^:]+/=combined' ( [^:] matches any character other than : ) + + Show accounts with the second-level part removed: + +--alias '/^([^:]+):[^:]+/ = \1' + match a top-level account and a second-level account + and replace those with just the top-level account + ( \1 in the replacement text means "whatever was matched + by the first parenthesised part of the regexp" + + CSV rules: match CSV records containing dining-related MCC codes: + +if \?MCC581[124] + + Match CSV records with a specific amount around the end/start of +month: + +if %amount \b3\.99 +& %date (29|30|31|01|02|03)$ + +* Menu: + +* hledger's regular expressions:: + + +File: hledger.info, Node: hledger's regular expressions, Up: Regular expressions + +5.4.1 hledger's regular expressions +----------------------------------- + +hledger's regular expressions come from the regex-tdfa library. If they're not doing what you expect, it's important to know exactly what they support: @@ -684,11 +751,10 @@ they support: being matched) 3. they are POSIX ERE (extended regular expressions) 4. they also support GNU word boundaries ('\b', '\B', '\<', '\>') - 5. they do not support backreferences; if you write '\1', it will - match the digit '1'. Except when doing text replacement, eg in - account aliases, where backreferences can be used in the + 5. backreferences are supported when doing text replacement in account + aliases or CSV rules, where backreferences can be used in the replacement string to reference capturing groups in the search - regexp. + regexp. Otherwise, if you write '\1', it will match the digit '1'. 6. they do not support mode modifiers ('(?s)'), character classes ('\w', '\d'), or anything else not mentioned above. @@ -765,7 +831,7 @@ File: hledger.info, Node: Output format, Next: Commodity styles, Prev: Output Some commands offer other kinds of output, not just text on the terminal. Here are those commands and the formats currently supported: -- txt csv html json sql +- txt csv/tsv html json sql ------------------------------------------------------------------------------- aregister Y Y Y Y balance Y _1_ Y _1_ Y _1,2_ Y @@ -1510,7 +1576,7 @@ File: hledger.info, Node: Decimal marks digit group marks, Next: Commodity, U A _decimal mark_ can be written as a period or a comma: 1.23 -1,23456780000009 +1,23 In the integer part of the quantity (left of the decimal mark), groups of digits can optionally be separated by a _digit group mark_ - a @@ -1521,21 +1587,15 @@ space, comma, or period (different from the decimal mark): INR 9,99,99,999.00 1 000 000.9455 - Note, a number containing a single digit group mark and no decimal -mark is ambiguous. Are these digit group marks or decimal marks ? + hledger is not biased towards period or comma decimal marks, so a +number containing just one period or comma, like '1,000' or '1.000', is +ambiguous. In such cases hledger assumes it is a decimal mark, parsing +both of these as 1. -1,000 -1.000 - - If you don't tell it otherwise, hledger will assume both of the above -are decimal marks, parsing both numbers as 1. - - To prevent confusing parsing mistakes and undetected typos, -especially if your data contains digit group marks (eg, thousands -separators), we recommend explicitly declaring the decimal mark -character in each journal file, using a directive at the top of the -file. The 'decimal-mark' directive is best, otherwise 'commodity' -directives will also work. These are described below. + To disambiguate these and ensure accurate number parsing, especially +if you use digit group marks, we recommend declaring the decimal mark. +You can declare it for each file with 'decimal-mark' directives, or for +each commodity with 'commodity' directives (described below).  File: hledger.info, Node: Commodity, Next: Directives influencing number parsing and display, Prev: Decimal marks digit group marks, Up: Amounts @@ -1589,55 +1649,34 @@ File: hledger.info, Node: Commodity display style, Next: Rounding, Prev: Dire ------------------------------ For the amounts in each commodity, hledger chooses a consistent display -style to use in most reports. (Exceptions: price amounts, and all -amounts displayed by the 'print' command, are displayed with all of -their decimal digits visible.) +style (symbol placement, decimal mark and digit group marks, number of +decimal digits) to use in most reports. This is inferred as follows: - A commodity's display style is inferred as follows. + First, if there's a 'D' directive declaring a default commodity, that +commodity symbol and amount format is applied to all no-symbol amounts +in the journal. - First, if a default commodity is declared with 'D', this commodity -and its style is applied to any no-symbol amounts in the journal. + Then each commodity's display style is determined from its +'commodity' directive. We recommend always declaring commodities with +'commodity' directives, since they help ensure consistent display styles +and precisions, and bring other benefits such as error checking for +commodity symbols. - Then each commodity's style is inferred from one of the following, in -order of preference: + But if a 'commodity' directive is not present, hledger infers a +commodity's display styles from its amounts as they are written in the +journal (excluding cost amounts and amounts in periodic transaction +rules or auto posting rules). It uses - * The commodity directive for that commodity (including the no-symbol - commodity), if any. - * The amounts in that commodity seen in the journal's transactions. - (Posting amounts only; prices and periodic or auto rules are - ignored, currently.) - * The built-in fallback style, which looks like this: '$1000.00'. - (Symbol on the left, period decimal mark, two decimal places.) + * the symbol placement and decimal mark of the first amount seen + * the digit group marks of the first amount with digit group marks + * and the maximum number of decimal digits seen across all amounts. - A style is inferred from journal amounts as follows: + And as fallback if no applicable amounts are found, it would use a +default style, like '$1000.00' (symbol on the left with no space, period +as decimal mark, and two decimal digits). - * Use the general style (decimal mark, symbol placement) of the first - amount - * Use the first-seen digit group style (digit group mark, digit group - sizes), if any - * Use the maximum number of decimal places of all. - - Cost amounts don't affect the commodity display style directly, but -occasionally they can do so indirectly (eg when a posting's amount is -inferred using a cost). If you find this causing problems, use a -commodity directive to fix the display style. - - To summarise: each commodity's amounts will be normalised to (a) the -style declared by a 'commodity' directive, or (b) the style of the first -posting amount in the journal, with the first-seen digit group style and -the maximum-seen number of decimal places. So if your reports are -showing amounts in a way you don't like, eg with too many decimal -places, use a commodity directive. Some examples: - -# declare euro, dollar, bitcoin and no-symbol commodities and set their -# input number formats and output display styles: -commodity EUR 1.000, -commodity $1000.00 -commodity 1000.00000000 BTC -commodity 1 000. - - The inferred commodity style can be overridden by supplying a command -line option. + Finally, commodity styles can be overridden by the +'-c/--commodity-style' command line option.  File: hledger.info, Node: Rounding, Prev: Commodity display style, Up: Amounts @@ -1646,10 +1685,12 @@ File: hledger.info, Node: Rounding, Prev: Commodity display style, Up: Amount --------------- Amounts are stored internally as decimal numbers with up to 255 decimal -places, and displayed with the number of decimal places specified by the -commodity display style. Note, hledger uses banker's rounding: it -rounds to the nearest even number, eg 0.5 displayed with zero decimal -places is "0"). +places. They are displayed with their original journal precisions by +print and print-like reports, and rounded to their display precision +(the number of decimal digits specified by the commodity display style) +by other reports. When rounding, hledger uses banker's rounding (it +rounds to the nearest even digit). So eg 0.5 displayed with zero +decimal digits appears as "0".  File: hledger.info, Node: Costs, Next: Balance assertions, Prev: Amounts, Up: Journal @@ -2653,93 +2694,90 @@ File: hledger.info, Node: commodity directive, Next: decimal-mark directive, 9.20 'commodity' directive ========================== -You can use 'commodity' directives to declare your commodities. In fact -the 'commodity' directive performs several functions at once: +The 'commodity' directive performs several functions: - 1. It declares commodities which may be used in the journal. This can - optionally be enforced, providing useful error checking. (Cf - Commodity error checking) + 1. It declares which commodity symbols may be used in the journal, + enabling useful error checking with strict mode or the check + command. (See Commodity error checking below.) - 2. It declares which decimal mark character (period or comma), to - expect when parsing input - useful to disambiguate international - number formats in your data. Without this, hledger will parse both - '1,000' and '1.000' as 1. (Cf Amounts) + 2. It declares the precision with which this commodity's amounts + should be compared when checking for balanced transactions. - 3. It declares how to render the commodity's amounts when displaying - output - the decimal mark, any digit group marks, the number of - decimal places, symbol placement and so on. (Cf Commodity display - style) + 3. It declares how this commodity's amounts should be displayed, eg + their symbol placement, digit group mark if any, digit group sizes, + decimal mark (period or comma), and the number of decimal places. + (See Commodity display style above.) - You will run into one of the problems solved by commodity directives -sooner or later, so we recommend using them, for robust and predictable -parsing and display. + 4. It sets which decimal mark (period or comma) to expect when parsing + subsequent amounts in this commodity (if there is no 'decimal-mark' + directive in effect. See Decimal marks, digit group marks above. + For related dev discussion, see #793.) - Generally you should put them at the top of your journal file (since -for function 2, they affect only following amounts, cf #793). + Declaring commodities solves several common parsing/display problems, +so we recommend it. Generally you should put 'commodity' directives at +the top of your journal file (because function 4 is position-sensitive). - A commodity directive is just the word 'commodity' followed by a -sample amount, like this: +* Menu: -;commodity SAMPLEAMOUNT +* Commodity directive syntax:: +* Commodity error checking:: + + +File: hledger.info, Node: Commodity directive syntax, Next: Commodity error checking, Up: commodity directive + +9.20.1 Commodity directive syntax +--------------------------------- + +A commodity directive is normally the word 'commodity' followed by a +sample amount (and optionally a comment). Only the amount's symbol and +format is significant. Eg: commodity $1000.00 -commodity 1,000.0000 AAAA ; optional same-line comment +commodity 1.000,00 EUR +commodity 1 000 000.0000 ; the no-symbol commodity - It may also be written on multiple lines, and use the 'format' -subdirective, as in Ledger. Note in this case the commodity symbol -appears twice; it must be the same in both places: + A commodity directive's sample amount must always include a period or +comma decimal mark (this rule helps disambiguate decimal marks and digit +group marks). If you don't want to show any decimal digits, write the +decimal mark at the end: -;commodity SYMBOL -; format SAMPLEAMOUNT +commodity 1000. AAAA ; show AAAA with no decimals + + Commodity symbols containing spaces, numbers, or punctuation must be +enclosed in double quotes, as usual: + +commodity 1.0000 "AAAA 2023" + + Commodity directives normally include a sample amount, but can +declare only a symbol (ie, just function 1 above): + +commodity $ +commodity INR +commodity "AAAA 2023" +commodity "" ; the no-symbol commodity + + Commodity directives may also be written with an indented 'format' +subdirective, as in Ledger. The symbol is repeated and must be the same +in both places. Other subdirectives are currently ignored: ; display indian rupees with currency name on the left, ; thousands, lakhs and crores comma-separated, ; period as decimal point, and two decimal places. commodity INR format INR 1,00,00,000.00 - - Other indented subdirectives are currently ignored. - - Remember that if the commodity symbol contains spaces, numbers, or -punctuation, it must be enclosed in double quotes (cf Commodity). - - The amount's quantity does not matter; only the format is -significant. It must include a decimal mark - either a period or a -comma - followed by 0 or more decimal digits. - - A few more examples: - -# number formats for $, EUR, INR and the no-symbol commodity: -commodity $1,000.00 -commodity EUR 1.000,00 -commodity INR 9,99,99,999.0 -commodity 1 000 000. - - Note hledger normally uses banker's rounding, so 0.5 displayed with -zero decimal digits is "0". (More at Commodity display style.) - - Even in the presence of commodity directives, the commodity display -style can still be overridden by supplying a command line option. - -* Menu: - -* Commodity error checking:: + an unsupported subdirective ; ignored by hledger  -File: hledger.info, Node: Commodity error checking, Up: commodity directive +File: hledger.info, Node: Commodity error checking, Prev: Commodity directive syntax, Up: commodity directive -9.20.1 Commodity error checking +9.20.2 Commodity error checking ------------------------------- -In strict mode, enabled with the '-s'/'--strict' flag, hledger will -report an error if a commodity symbol is used that has not been declared -by a 'commodity' directive. This works similarly to account error -checking, see the notes there for more details. - - Note, this disallows amounts without a commodity symbol, because -currently it's not possible (?) to declare the "no-symbol" commodity -with a directive. This is one exception for convenience: zero amounts -are always allowed to have no commodity symbol. +In strict mode ('-s'/'--strict') (or when you run 'hledger check +commodities'), hledger will report an error if an undeclared commodity +symbol is used. (With one exception: zero amounts are always allowed to +have no commodity symbol.) It works like account error checking +(described above).  File: hledger.info, Node: decimal-mark directive, Next: include directive, Prev: commodity directive, Up: Journal @@ -3839,9 +3877,9 @@ list (see above). To assign a value to a hledger field, write the field name (any of the standard hledger field/pseudo-field names, defined below), a space, followed by a text value on the same line. This text value may -interpolate CSV fields, referenced by their 1-based position in the CSV -record ('%N'), or by the name they were given in the fields list -('%CSVFIELD'). +interpolate CSV fields, referenced either by their 1-based position in +the CSV record ('%N') or by the name they were given in the fields list +('%CSVFIELD'), and regular expression match groups ('\N'). Some examples: @@ -4165,7 +4203,38 @@ the original record was: * When a matcher is preceded by ampersand ('&') it will be AND'ed with the previous matcher (both of them must match). - There's not yet an easy syntax to negate a matcher. + When a matcher is preceded by an exclamation mark (!), the matcher +will be negated, ie it will exclude CSV records that match. + +* Menu: + +* Match groups:: + + +File: hledger.info, Node: Match groups, Up: Matchers + +10.14.1 Match groups +-------------------- + +Matchers can define match groups: parenthesised portions of the regular +expression which are available for reference in field assignments. +Groups are enclosed in regular parentheses ('(' and ')') and can be +nested. Each group is available in field assignments using the token +'\N', where N is an index into the match groups for this conditional +block (e.g. '\1', '\2', etc.). + + Example: Warp credit card payment postings to the beginning of the +billing period (Month start), to match how they are presented in +statements, using posting dates: + +if %date (....-..)-.. + comment2 date:\1-01 + + Another example: Read the expense account from the CSV field, but +throw away a prefix: + +if %account1 liabilities:family:(expenses:.*) + account1 \1  File: hledger.info, Node: if table, Next: balance-type, Prev: Matchers, Up: CSV @@ -4183,18 +4252,21 @@ MATCHERB,VALUE1,VALUE2,... MATCHERC,VALUE1,VALUE2,... - The first character after 'if' is taken to be the separator for the -rest of the table. It should be a non-alphanumeric character like ',' -or '|' that does not appear anywhere else in the table. (Note: it is -unrelated to the CSV file's separator.) Whitespace can be used in the -matcher lines for readability, but not in the if line currently. The -table must be terminated by an empty line (or end of file). Each line -must contain the same number of separators; empty values are allowed. + The first character after 'if' is taken to be this if table's field +separator. It is unrelated to the separator used in the CSV file. It +should be a non-alphanumeric character like ',' or '|' that does not +appear anywhere else in the table (it should not be used in field names +or matchers or values, and it cannot be escaped with a backslash). - The above means: try all of the matchers; whenever a matcher -succeeds, assign all of the values on that line to the corresponding -hledger fields; later lines can overrider earlier ones. It is -equivalent to this sequence of if blocks: + Each line must contain the same number of separators; empty values +are allowed. Whitespace can be used in the matcher lines for +readability (but not in the if line, currently). The table must be +terminated by an empty line (or end of file). + + An if table like the above is interpreted as follows: try all of the +matchers; whenever a matcher succeeds, assign all of the values on that +line to the corresponding hledger fields; later lines can overrider +earlier ones. It is equivalent to this sequence of if blocks: if MATCHERA HLEDGERFIELD1 VALUE1 @@ -5217,15 +5289,60 @@ $ hledger -f a.timedot --alias /\\./=: bal --tree A sample.timedot file.  -File: hledger.info, Node: PART 3 REPORTING CONCEPTS, Next: Time periods, Prev: Timedot, Up: Top +File: hledger.info, Node: PART 3 REPORTING CONCEPTS, Next: Amount formatting parseability, Prev: Timedot, Up: Top 13 PART 3: REPORTING CONCEPTS *****************************  -File: hledger.info, Node: Time periods, Next: Depth, Prev: PART 3 REPORTING CONCEPTS, Up: Top +File: hledger.info, Node: Amount formatting parseability, Next: Time periods, Prev: PART 3 REPORTING CONCEPTS, Up: Top -14 Time periods +14 Amount formatting, parseability +********************************** + +If you're wondering why your 'print' report sometimes shows trailing +decimal marks, even when there are no decimal digits; it does this to +disambiguate ambiguous amounts (amounts which have one digit group mark +and no decimal digits), allowing them to be re-parsed reliably. + + More generally: hledger output falls into three rough categories, +which format amounts a little bit differently to suit different +consumers: + + *1. "hledger-readable output" - should be readable by hledger (and +by humans)* + + * This is produced by reports that show full journal entries: + 'print', 'import', 'close', 'rewrite' etc. + * It shows amounts with their original journal precisions, which may + not be consistent. + * It adds a trailing decimal mark when needed to avoid showing + ambiguous amounts. + * It can be parsed reliably (by hledger and ledger2beancount at + least, but perhaps not by Ledger..) + + *2. "human-readable output" - usually for humans* + + * This is produced by all other reports. + * It shows amounts with standard display precisions, which will be + consistent within each commodity. + * It shows ambiguous amounts unmodified. + * It can be parsed reliably in the context of a known report (when + you know decimals are consistently not being shown, you can assume + a single mark is a digit group mark). + + *3. "machine-readable output" - usually for other software* + + * This is produced by all reports when an output format like 'csv', + 'tsv', 'json', or 'sql' is selected. + * It shows amounts as 1 or 2 do, but without digit group marks. + * It can be parsed reliably (if needed, the decimal mark can be + changed with -c/-commodity-style). + + +File: hledger.info, Node: Time periods, Next: Depth, Prev: Amount formatting parseability, Up: Top + +15 Time periods *************** * Menu: @@ -5239,7 +5356,7 @@ File: hledger.info, Node: Time periods, Next: Depth, Prev: PART 3 REPORTING C  File: hledger.info, Node: Report start & end date, Next: Smart dates, Up: Time periods -14.1 Report start & end date +15.1 Report start & end date ============================ By default, most hledger reports will show the full span of time @@ -5284,7 +5401,7 @@ thismonth'  File: hledger.info, Node: Smart dates, Next: Report intervals, Prev: Report start & end date, Up: Time periods -14.2 Smart dates +15.2 Smart dates ================ hledger's user interfaces accept a "smart date" syntax for added @@ -5333,7 +5450,7 @@ periodic transaction rules, which are not affected by '--today'.)  File: hledger.info, Node: Report intervals, Next: Date adjustment, Prev: Smart dates, Up: Time periods -14.3 Report intervals +15.3 Report intervals ===================== A report interval can be specified so that reports like register, @@ -5355,7 +5472,7 @@ described below.  File: hledger.info, Node: Date adjustment, Next: Period expressions, Prev: Report intervals, Up: Time periods -14.4 Date adjustment +15.4 Date adjustment ==================== When there is a report interval (other than daily), report start/end @@ -5379,7 +5496,7 @@ period headings.  File: hledger.info, Node: Period expressions, Prev: Date adjustment, Up: Time periods -14.5 Period expressions +15.5 Period expressions ======================= The '-p/--period' option specifies a period expression, which is a @@ -5439,7 +5556,7 @@ date:  File: hledger.info, Node: Period expressions with a report interval, Next: More complex report intervals, Up: Period expressions -14.5.1 Period expressions with a report interval +15.5.1 Period expressions with a report interval ------------------------------------------------ A period expression can also begin with a report interval, separated @@ -5452,7 +5569,7 @@ from the start/end dates (if any) by a space or the word 'in':  File: hledger.info, Node: More complex report intervals, Next: Multiple weekday intervals, Prev: Period expressions with a report interval, Up: Period expressions -14.5.2 More complex report intervals +15.5.2 More complex report intervals ------------------------------------ Some more complex intervals can be specified within period expressions, @@ -5515,7 +5632,7 @@ $ hledger register checking -p "every 3rd day of week"  File: hledger.info, Node: Multiple weekday intervals, Prev: More complex report intervals, Up: Period expressions -14.5.3 Multiple weekday intervals +15.5.3 Multiple weekday intervals --------------------------------- This special form is also supported: @@ -5543,7 +5660,7 @@ weekendday"'  File: hledger.info, Node: Depth, Next: Queries, Prev: Time periods, Up: Top -15 Depth +16 Depth ******** With the '--depth NUM' option (short form: '-NUM'), reports will show @@ -5555,7 +5672,7 @@ equivalent.  File: hledger.info, Node: Queries, Next: Pivoting, Prev: Depth, Up: Top -16 Queries +17 Queries ********** One of hledger's strengths is being able to quickly report on a precise @@ -5607,7 +5724,7 @@ arguments to restrict their scope. The syntax is as follows:  File: hledger.info, Node: Query types, Next: Combining query terms, Up: Queries -16.1 Query types +17.1 Query types ================ Here are the types of query term available. Remember these can also be @@ -5700,7 +5817,7 @@ hledger-web to show the transaction register for an account.)  File: hledger.info, Node: Combining query terms, Next: Queries and command options, Prev: Query types, Up: Queries -16.2 Combining query terms +17.2 Combining query terms ========================== When given multiple space-separated query terms, most commands select @@ -5744,7 +5861,7 @@ OR, and NOT, where NOT is different syntax for 'not:'.  File: hledger.info, Node: Queries and command options, Next: Queries and valuation, Prev: Combining query terms, Up: Queries -16.3 Queries and command options +17.3 Queries and command options ================================ Some queries can also be expressed as command-line options: 'depth:2' is @@ -5755,7 +5872,7 @@ resulting query is their intersection.  File: hledger.info, Node: Queries and valuation, Next: Querying with account aliases, Prev: Queries and command options, Up: Queries -16.4 Queries and valuation +17.4 Queries and valuation ========================== When amounts are converted to other commodities in cost or value @@ -5766,7 +5883,7 @@ reversed, see #1625).  File: hledger.info, Node: Querying with account aliases, Next: Querying with cost or value, Prev: Queries and valuation, Up: Queries -16.5 Querying with account aliases +17.5 Querying with account aliases ================================== When account names are rewritten with '--alias' or 'alias', note that @@ -5775,7 +5892,7 @@ When account names are rewritten with '--alias' or 'alias', note that  File: hledger.info, Node: Querying with cost or value, Prev: Querying with account aliases, Up: Queries -16.6 Querying with cost or value +17.6 Querying with cost or value ================================ When amounts are converted to other commodities in cost or value @@ -5787,7 +5904,7 @@ the discussion at #1625.  File: hledger.info, Node: Pivoting, Next: Generating data, Prev: Queries, Up: Top -17 Pivoting +18 Pivoting *********** Normally, hledger groups and sums amounts within each account. The @@ -5848,7 +5965,7 @@ $ hledger balance Income:Dues --pivot kind:member  File: hledger.info, Node: Generating data, Next: Forecasting, Prev: Pivoting, Up: Top -18 Generating data +19 Generating data ****************** hledger has several features for generating data, such as: @@ -5887,7 +6004,7 @@ prefix), so eg you could match generated transactions with  File: hledger.info, Node: Forecasting, Next: Budgeting, Prev: Generating data, Up: Top -19 Forecasting +20 Forecasting ************** Forecasting, or speculative future reporting, can be useful for @@ -5910,7 +6027,7 @@ when you want to see them.  File: hledger.info, Node: --forecast, Next: Inspecting forecast transactions, Up: Forecasting -19.1 -forecast +20.1 -forecast ============== There is another way: with the '--forecast' option, hledger can generate @@ -5935,7 +6052,7 @@ that the '=' is required.  File: hledger.info, Node: Inspecting forecast transactions, Next: Forecast reports, Prev: --forecast, Up: Forecasting -19.2 Inspecting forecast transactions +20.2 Inspecting forecast transactions ===================================== 'print' is the best command for inspecting and troubleshooting forecast @@ -5979,7 +6096,7 @@ reproducible.)  File: hledger.info, Node: Forecast reports, Next: Forecast tags, Prev: Inspecting forecast transactions, Up: Forecasting -19.3 Forecast reports +20.3 Forecast reports ===================== Forecast transactions affect all reports, as you would expect. Eg: @@ -6004,7 +6121,7 @@ Balance changes in 2023-05-01..2023-09-30:  File: hledger.info, Node: Forecast tags, Next: Forecast period in detail, Prev: Forecast reports, Up: Forecasting -19.4 Forecast tags +20.4 Forecast tags ================== Forecast transactions generated by -forecast have a hidden tag, @@ -6020,7 +6137,7 @@ rule was responsible.  File: hledger.info, Node: Forecast period in detail, Next: Forecast troubleshooting, Prev: Forecast tags, Up: Forecasting -19.5 Forecast period, in detail +20.5 Forecast period, in detail =============================== Forecast start/end dates are chosen so as to do something useful by @@ -6051,7 +6168,7 @@ default in almost all situations, while also being flexible. Here are  File: hledger.info, Node: Forecast troubleshooting, Prev: Forecast period in detail, Up: Forecasting -19.6 Forecast troubleshooting +20.6 Forecast troubleshooting ============================= When -forecast is not doing what you expect, one of these tips should @@ -6079,7 +6196,7 @@ help:  File: hledger.info, Node: Budgeting, Next: Cost reporting, Prev: Forecasting, Up: Top -20 Budgeting +21 Budgeting ************ With the balance command's '--budget' report, each periodic transaction @@ -6096,7 +6213,7 @@ bal -M --budget --forecast ...'  File: hledger.info, Node: Cost reporting, Next: Value reporting, Prev: Budgeting, Up: Top -21 Cost reporting +22 Cost reporting ***************** In some transactions - for example a currency conversion, or a purchase @@ -6119,7 +6236,7 @@ rate" or "selling price" if helpful.  File: hledger.info, Node: Recording costs, Next: Reporting at cost, Up: Cost reporting -21.1 Recording costs +22.1 Recording costs ==================== We'll explore several ways of recording transactions involving costs. @@ -6173,7 +6290,7 @@ sure you have none of these by using '-s' (strict mode), or by running  File: hledger.info, Node: Reporting at cost, Next: Equity conversion postings, Prev: Recording costs, Up: Cost reporting -21.2 Reporting at cost +22.2 Reporting at cost ====================== Now when you add the '-B'/'--cost' flag to reports ("B" is from Ledger's @@ -6193,7 +6310,7 @@ they will be displayed "at cost" or "at sale price".  File: hledger.info, Node: Equity conversion postings, Next: Inferring equity conversion postings, Prev: Reporting at cost, Up: Cost reporting -21.3 Equity conversion postings +22.3 Equity conversion postings =============================== There is a problem with the entries above - they are not conventional @@ -6249,7 +6366,7 @@ $ hledger bal --infer-costs -B  File: hledger.info, Node: Inferring equity conversion postings, Next: Combining costs and equity conversion postings, Prev: Equity conversion postings, Up: Cost reporting -21.4 Inferring equity conversion postings +22.4 Inferring equity conversion postings ========================================= Can we go in the other direction ? Yes, if you have transactions @@ -6275,7 +6392,7 @@ account with the 'V'/'Conversion' account type.  File: hledger.info, Node: Combining costs and equity conversion postings, Next: Requirements for detecting equity conversion postings, Prev: Inferring equity conversion postings, Up: Cost reporting -21.5 Combining costs and equity conversion postings +22.5 Combining costs and equity conversion postings =================================================== Finally, you can use both the @/@@ cost notation and equity postings at @@ -6311,7 +6428,7 @@ $ hledger print -x --infer-costs --infer-equity  File: hledger.info, Node: Requirements for detecting equity conversion postings, Next: Infer cost and equity by default ?, Prev: Combining costs and equity conversion postings, Up: Cost reporting -21.6 Requirements for detecting equity conversion postings +22.6 Requirements for detecting equity conversion postings ========================================================== '--infer-costs' has certain requirements (unlike '--infer-equity', which @@ -6342,7 +6459,7 @@ fails, hledger raises an "unbalanced transaction" error.  File: hledger.info, Node: Infer cost and equity by default ?, Prev: Requirements for detecting equity conversion postings, Up: Cost reporting -21.7 Infer cost and equity by default ? +22.7 Infer cost and equity by default ? ======================================= Should '--infer-costs' and '--infer-equity' be enabled by default ? Try @@ -6355,7 +6472,7 @@ alias h="hledger --infer-equity --infer-costs"  File: hledger.info, Node: Value reporting, Next: PART 4 COMMANDS, Prev: Cost reporting, Up: Top -22 Value reporting +23 Value reporting ****************** Instead of reporting amounts in their original commodity, hledger can @@ -6382,7 +6499,7 @@ and '-X COMMODITY' options, and often one of these is all you need:  File: hledger.info, Node: -V Value, Next: -X Value in specified commodity, Up: Value reporting -22.1 -V: Value +23.1 -V: Value ============== The '-V/--market' flag converts amounts to market value in their default @@ -6392,7 +6509,7 @@ _valuation date(s)_, if any. More on these in a minute.  File: hledger.info, Node: -X Value in specified commodity, Next: Valuation date, Prev: -V Value, Up: Value reporting -22.2 -X: Value in specified commodity +23.2 -X: Value in specified commodity ===================================== The '-X/--exchange=COMM' option is like '-V', except you tell it which @@ -6402,29 +6519,35 @@ that.  File: hledger.info, Node: Valuation date, Next: Finding market price, Prev: -X Value in specified commodity, Up: Value reporting -22.3 Valuation date +23.3 Valuation date =================== -Since market prices can change from day to day, market value reports -have a valuation date (or more than one), which determines which market -prices will be used. +Market prices can change from day to day. hledger will use the prices +on a particular valuation date (or on more than one date). By default +hledger uses "end" dates for valuation. More specifically: - For single period reports, if an explicit report end date is -specified, that will be used as the valuation date; otherwise the -valuation date is the journal's end date. + * For single period reports (including normal print and register + reports): + * If an explicit report end date is specified, that is used + * Otherwise the latest transaction date or P directive date is + used (even if it's in the future) - For multiperiod reports, each column/period is valued on the last day -of the period, by default. + * For multiperiod reports, each period is valued on its last day. + + This can be customised with the -value option described below, which +can select either "then", "end", "now", or "custom" dates. (Note, this +has a bug in hledger-ui <=1.31: turning on valuation with the 'V' key +always resets it to "end".)  File: hledger.info, Node: Finding market price, Next: --infer-market-prices market prices from transactions, Prev: Valuation date, Up: Value reporting -22.4 Finding market price +23.4 Finding market price ========================= To convert a commodity A to its market value in another commodity B, hledger looks for a suitable market price (exchange rate) as follows, in -this order of preference : +this order of preference: 1. A _declared market price_ or _inferred market price_: A's latest market price in B on or before the valuation date as declared by a @@ -6453,7 +6576,7 @@ converted.  File: hledger.info, Node: --infer-market-prices market prices from transactions, Next: Valuation commodity, Prev: Finding market price, Up: Value reporting -22.5 -infer-market-prices: market prices from transactions +23.5 -infer-market-prices: market prices from transactions ========================================================== Normally, market value in hledger is fully controlled by, and requires, @@ -6539,7 +6662,7 @@ P 2022-01-03 B A -1.0  File: hledger.info, Node: Valuation commodity, Next: Simple valuation examples, Prev: --infer-market-prices market prices from transactions, Up: Value reporting -22.6 Valuation commodity +23.6 Valuation commodity ======================== *When you specify a valuation commodity ('-X COMM' or '--value @@ -6578,7 +6701,7 @@ converted.  File: hledger.info, Node: Simple valuation examples, Next: --value Flexible valuation, Prev: Valuation commodity, Up: Value reporting -22.7 Simple valuation examples +23.7 Simple valuation examples ============================== Here are some quick examples of '-V': @@ -6613,7 +6736,7 @@ $ hledger -f t.j bal -N euros -V  File: hledger.info, Node: --value Flexible valuation, Next: More valuation examples, Prev: Simple valuation examples, Up: Value reporting -22.8 -value: Flexible valuation +23.8 -value: Flexible valuation =============================== '-V' and '-X' are special cases of the more general '--value' option: @@ -6655,7 +6778,7 @@ this commodity, deducing market prices as described above.  File: hledger.info, Node: More valuation examples, Next: Interaction of valuation and queries, Prev: --value Flexible valuation, Up: Value reporting -22.9 More valuation examples +23.9 More valuation examples ============================ Here are some examples showing the effect of '--value', as seen with @@ -6734,42 +6857,10 @@ $ hledger -f- print --value=2000-01-15 2000-03-01 (a) 1 B - You may need to explicitly set a commodity's display style, when -reverse prices are used. Eg this output might be surprising: - -P 2000-01-01 A 2B - -2000-01-01 - a 1B - b - -$ hledger print -x -X A -2000-01-01 - a 0 - b 0 - - Explanation: because there's no amount or commodity directive -specifying a display style for A, 0.5A gets the default style, which -shows no decimal digits. Because the displayed amount looks like zero, -the commodity symbol and minus sign are not displayed either. Adding a -commodity directive sets a more useful display style for A: - -P 2000-01-01 A 2B -commodity 0.00A - -2000-01-01 - a 1B - b - -$ hledger print -X A -2000-01-01 - a 0.50A - b -0.50A -  File: hledger.info, Node: Interaction of valuation and queries, Next: Effect of valuation on reports, Prev: More valuation examples, Up: Value reporting -22.10 Interaction of valuation and queries +23.10 Interaction of valuation and queries ========================================== When matching postings based on queries in the presence of valuation, @@ -6790,7 +6881,7 @@ the following happens.  File: hledger.info, Node: Effect of valuation on reports, Prev: Interaction of valuation and queries, Up: Value reporting -22.11 Effect of valuation on reports +23.11 Effect of valuation on reports ==================================== Here is a reference for how valuation is supposed to affect each part of @@ -6939,7 +7030,7 @@ _report interval_  File: hledger.info, Node: PART 4 COMMANDS, Next: PART 5 COMMON TASKS, Prev: Value reporting, Up: Top -23 PART 4: COMMANDS +24 PART 4: COMMANDS ******************* * Menu: @@ -6978,7 +7069,7 @@ File: hledger.info, Node: PART 4 COMMANDS, Next: PART 5 COMMON TASKS, Prev: V  File: hledger.info, Node: Commands overview, Next: accounts, Up: PART 4 COMMANDS -23.1 Commands overview +24.1 Commands overview ====================== Here are the built-in commands: @@ -6997,7 +7088,7 @@ Here are the built-in commands:  File: hledger.info, Node: DATA ENTRY, Next: DATA CREATION, Up: Commands overview -23.1.1 DATA ENTRY +24.1.1 DATA ENTRY ----------------- These data entry commands are the only ones which can modify your @@ -7009,7 +7100,7 @@ journal file.  File: hledger.info, Node: DATA CREATION, Next: DATA MANAGEMENT, Prev: DATA ENTRY, Up: Commands overview -23.1.2 DATA CREATION +24.1.2 DATA CREATION -------------------- * close - generate balance-zeroing/restoring transactions @@ -7018,7 +7109,7 @@ File: hledger.info, Node: DATA CREATION, Next: DATA MANAGEMENT, Prev: DATA EN  File: hledger.info, Node: DATA MANAGEMENT, Next: REPORTS FINANCIAL, Prev: DATA CREATION, Up: Commands overview -23.1.3 DATA MANAGEMENT +24.1.3 DATA MANAGEMENT ---------------------- * check - check for various kinds of error in the data @@ -7027,7 +7118,7 @@ File: hledger.info, Node: DATA MANAGEMENT, Next: REPORTS FINANCIAL, Prev: DAT  File: hledger.info, Node: REPORTS FINANCIAL, Next: REPORTS VERSATILE, Prev: DATA MANAGEMENT, Up: Commands overview -23.1.4 REPORTS, FINANCIAL +24.1.4 REPORTS, FINANCIAL ------------------------- * aregister (areg) - show transactions in a particular account @@ -7039,7 +7130,7 @@ File: hledger.info, Node: REPORTS FINANCIAL, Next: REPORTS VERSATILE, Prev: D  File: hledger.info, Node: REPORTS VERSATILE, Next: REPORTS BASIC, Prev: REPORTS FINANCIAL, Up: Commands overview -23.1.5 REPORTS, VERSATILE +24.1.5 REPORTS, VERSATILE ------------------------- * balance (bal) - show balance changes, end balances, budgets, @@ -7052,7 +7143,7 @@ File: hledger.info, Node: REPORTS VERSATILE, Next: REPORTS BASIC, Prev: REPOR  File: hledger.info, Node: REPORTS BASIC, Next: HELP, Prev: REPORTS VERSATILE, Up: Commands overview -23.1.6 REPORTS, BASIC +24.1.6 REPORTS, BASIC --------------------- * accounts - show account names @@ -7071,7 +7162,7 @@ File: hledger.info, Node: REPORTS BASIC, Next: HELP, Prev: REPORTS VERSATILE,  File: hledger.info, Node: HELP, Next: ADD-ONS, Prev: REPORTS BASIC, Up: Commands overview -23.1.7 HELP +24.1.7 HELP ----------- * help - show the hledger manual with info/man/pager @@ -7080,7 +7171,7 @@ File: hledger.info, Node: HELP, Next: ADD-ONS, Prev: REPORTS BASIC, Up: Comm  File: hledger.info, Node: ADD-ONS, Prev: HELP, Up: Commands overview -23.1.8 ADD-ONS +24.1.8 ADD-ONS -------------- And here are some typical add-on commands. Some of these are installed @@ -7100,7 +7191,7 @@ hledger's commands list:  File: hledger.info, Node: accounts, Next: activity, Prev: Commands overview, Up: PART 4 COMMANDS -23.2 accounts +24.2 accounts ============= Show account names. @@ -7157,7 +7248,7 @@ $ hledger check accounts  File: hledger.info, Node: activity, Next: add, Prev: accounts, Up: PART 4 COMMANDS -23.3 activity +24.3 activity ============= Show an ascii barchart of posting counts per interval. @@ -7177,7 +7268,7 @@ $ hledger activity --quarterly  File: hledger.info, Node: add, Next: aregister, Prev: activity, Up: PART 4 COMMANDS -23.4 add +24.4 add ======== Prompt for transactions and add them to the journal. Any arguments will @@ -7247,7 +7338,7 @@ file path ends with a period, as that would cause problems (#1056).  File: hledger.info, Node: aregister, Next: balance, Prev: add, Up: PART 4 COMMANDS -23.5 aregister +24.5 aregister ============== (areg) @@ -7313,32 +7404,37 @@ ensure perfect alignment, at the cost of more time and memory, use the '--align-all' flag. This command also supports the output destination and output format -options. The output formats supported are 'txt', 'csv', and 'json'. +options. The output formats supported are 'txt', 'csv', 'tsv', and +'json'. * Menu: -* aregister and custom posting dates:: +* aregister and posting dates::  -File: hledger.info, Node: aregister and custom posting dates, Up: aregister +File: hledger.info, Node: aregister and posting dates, Up: aregister -23.5.1 aregister and custom posting dates ------------------------------------------ +24.5.1 aregister and posting dates +---------------------------------- -Transactions whose date is outside the report period can still be shown, -if they have a posting to this account dated inside the report period. -(And in this case it's the posting date that is shown.) This ensures -that 'aregister' can show an accurate historical running balance, -matching the one shown by 'register -H' with the same arguments. +aregister always shows one line (and date and amount) per transaction. +But sometimes transactions have postings with different dates. Also, +not all of a transaction's postings may be within the report period. To +resolve this, aregister shows the earliest of the transaction's date and +posting dates that is in-period, and the sum of the in-period postings. +In other words it will show a combined line item with just the earliest +date, and the running balance will (temporarily, until the transaction's +last posting) be inaccurate. Use 'register -H' if you need to see the +individual postings. - To filter strictly by transaction date instead, add the '--txn-dates' -flag. If you use this flag and some of your postings have custom dates, -it's probably best to assume the running balance is wrong. + There is also a '--txn-dates' flag, which filters strictly by +transaction date, ignoring posting dates. This too can cause an +inaccurate running balance.  File: hledger.info, Node: balance, Next: balancesheet, Prev: aregister, Up: PART 4 COMMANDS -23.6 balance +24.6 balance ============ (bal) @@ -7377,7 +7473,7 @@ more control, then use 'balance'.  File: hledger.info, Node: balance features, Next: Simple balance report, Up: balance -23.6.1 balance features +24.6.1 balance features ----------------------- Here's a quick overview of the 'balance' command's features, followed by @@ -7430,9 +7526,9 @@ higher-level commands as well. ('--layout') This command supports the output destination and output format -options, with output formats 'txt', 'csv', 'json', and (multi-period -reports only:) 'html'. In 'txt' output in a colour-supporting terminal, -negative amounts are shown in red. +options, with output formats 'txt', 'csv', 'tsv', 'json', and +(multi-period reports only:) 'html'. In 'txt' output in a +colour-supporting terminal, negative amounts are shown in red. The '--related'/'-r' flag shows the balance of the _other_ postings in the transactions of the postings which would normally be shown. @@ -7440,7 +7536,7 @@ in the transactions of the postings which would normally be shown.  File: hledger.info, Node: Simple balance report, Next: Balance report line format, Prev: balance features, Up: balance -23.6.2 Simple balance report +24.6.2 Simple balance report ---------------------------- With no arguments, 'balance' shows a list of all accounts and their @@ -7489,7 +7585,7 @@ $ hledger -f examples/sample.journal bal -E  File: hledger.info, Node: Balance report line format, Next: Filtered balance report, Prev: Simple balance report, Up: balance -23.6.3 Balance report line format +24.6.3 Balance report line format --------------------------------- For single-period balance reports displayed in the terminal (only), you @@ -7552,7 +7648,7 @@ may be needed to get pleasing results.  File: hledger.info, Node: Filtered balance report, Next: List or tree mode, Prev: Balance report line format, Up: balance -23.6.4 Filtered balance report +24.6.4 Filtered balance report ------------------------------ You can show fewer accounts, a different time period, totals from @@ -7567,7 +7663,7 @@ $ hledger -f examples/sample.journal bal --cleared assets date:200806  File: hledger.info, Node: List or tree mode, Next: Depth limiting, Prev: Filtered balance report, Up: balance -23.6.5 List or tree mode +24.6.5 List or tree mode ------------------------ By default, or with '-l/--flat', accounts are shown as a flat list with @@ -7610,7 +7706,7 @@ $ hledger -f examples/sample.journal balance  File: hledger.info, Node: Depth limiting, Next: Dropping top-level accounts, Prev: List or tree mode, Up: balance -23.6.6 Depth limiting +24.6.6 Depth limiting --------------------- With a 'depth:NUM' query, or '--depth NUM' option, or just '-NUM' (eg: @@ -7632,7 +7728,7 @@ $ hledger -f examples/sample.journal balance -1  File: hledger.info, Node: Dropping top-level accounts, Next: Showing declared accounts, Prev: Depth limiting, Up: balance -23.6.7 Dropping top-level accounts +24.6.7 Dropping top-level accounts ---------------------------------- You can also hide one or more top-level account name parts, using @@ -7648,7 +7744,7 @@ $ hledger -f examples/sample.journal bal expenses --drop 1  File: hledger.info, Node: Showing declared accounts, Next: Sorting by amount, Prev: Dropping top-level accounts, Up: balance -23.6.8 Showing declared accounts +24.6.8 Showing declared accounts -------------------------------- With '--declared', accounts which have been declared with an account @@ -7666,7 +7762,7 @@ accounts yet.  File: hledger.info, Node: Sorting by amount, Next: Percentages, Prev: Showing declared accounts, Up: balance -23.6.9 Sorting by amount +24.6.9 Sorting by amount ------------------------ With '-S/--sort-amount', accounts with the largest (most positive) @@ -7684,7 +7780,7 @@ which flip the sign automatically. Eg: 'hledger incomestatement -MAS').  File: hledger.info, Node: Percentages, Next: Multi-period balance report, Prev: Sorting by amount, Up: balance -23.6.10 Percentages +24.6.10 Percentages ------------------- With '-%/--percent', balance reports show each account's value expressed @@ -7707,7 +7803,7 @@ $ hledger bal -% cur:€  File: hledger.info, Node: Multi-period balance report, Next: Balance change end balance, Prev: Percentages, Up: balance -23.6.11 Multi-period balance report +24.6.11 Multi-period balance report ----------------------------------- With a report interval (set by the '-D/--daily', '-W/--weekly', @@ -7762,7 +7858,7 @@ viewing in the terminal. Here are some ways to handle that:  File: hledger.info, Node: Balance change end balance, Next: Balance report types, Prev: Multi-period balance report, Up: balance -23.6.12 Balance change, end balance +24.6.12 Balance change, end balance ----------------------------------- It's important to be clear on the meaning of the numbers shown in @@ -7799,7 +7895,7 @@ historical end balances:  File: hledger.info, Node: Balance report types, Next: Budget report, Prev: Balance change end balance, Up: balance -23.6.13 Balance report types +24.6.13 Balance report types ---------------------------- The balance command is quite flexible; here is the full detail on how to @@ -7822,7 +7918,7 @@ experimentation to get familiar with all the report modes.  File: hledger.info, Node: Calculation type, Next: Accumulation type, Up: Balance report types -23.6.13.1 Calculation type +24.6.13.1 Calculation type .......................... The basic calculation to perform for each table cell. It is one of: @@ -7840,7 +7936,7 @@ The basic calculation to perform for each table cell. It is one of:  File: hledger.info, Node: Accumulation type, Next: Valuation type, Prev: Calculation type, Up: Balance report types -23.6.13.2 Accumulation type +24.6.13.2 Accumulation type ........................... How amounts should accumulate across report periods. Another way to say @@ -7865,7 +7961,7 @@ calculation. It is one of:  File: hledger.info, Node: Valuation type, Next: Combining balance report types, Prev: Accumulation type, Up: Balance report types -23.6.13.3 Valuation type +24.6.13.3 Valuation type ........................ Which kind of value or cost conversion should be applied, if any, before @@ -7896,7 +7992,7 @@ displaying the report. It is one of:  File: hledger.info, Node: Combining balance report types, Prev: Valuation type, Up: Balance report types -23.6.13.4 Combining balance report types +24.6.13.4 Combining balance report types ........................................ Most combinations of these options should produce reasonable reports, @@ -7935,7 +8031,7 @@ Accumulation:v YYYY-MM-DD  File: hledger.info, Node: Budget report, Next: Balance report layout, Prev: Balance report types, Up: balance -23.6.14 Budget report +24.6.14 Budget report --------------------- The '--budget' report type activates extra columns showing any budget @@ -8070,7 +8166,7 @@ currencies, '--layout bare' or '--layout tall' can help.  File: hledger.info, Node: Budget report start date, Next: Budgets and subaccounts, Up: Budget report -23.6.14.1 Budget report start date +24.6.14.1 Budget report start date .................................. This might be a bug, but for now: when making budget reports, it's a @@ -8114,7 +8210,7 @@ Budget performance in 2020-01-01..2020-01-15:  File: hledger.info, Node: Budgets and subaccounts, Next: Selecting budget goals, Prev: Budget report start date, Up: Budget report -23.6.14.2 Budgets and subaccounts +24.6.14.2 Budgets and subaccounts ................................. You can add budgets to any account in your account hierarchy. If you @@ -8202,7 +8298,7 @@ Budget performance in 2019/01:  File: hledger.info, Node: Selecting budget goals, Next: Budget vs forecast, Prev: Budgets and subaccounts, Up: Budget report -23.6.14.3 Selecting budget goals +24.6.14.3 Selecting budget goals ................................ The budget report evaluates periodic transaction rules to generate @@ -8228,7 +8324,7 @@ select from multiple budgets defined in your journal.  File: hledger.info, Node: Budget vs forecast, Prev: Selecting budget goals, Up: Budget report -23.6.14.4 Budget vs forecast +24.6.14.4 Budget vs forecast ............................ 'hledger --forecast ...' and 'hledger balance --budget ...' are separate @@ -8276,7 +8372,7 @@ time if you want. Here are some differences between them, as of hledger  File: hledger.info, Node: Balance report layout, Next: Useful balance reports, Prev: Budget report, Up: balance -23.6.15 Balance report layout +24.6.15 Balance report layout ----------------------------- The '--layout' option affects how balance reports show multi-commodity @@ -8417,7 +8513,7 @@ tidy Y  File: hledger.info, Node: Useful balance reports, Prev: Balance report layout, Up: balance -23.6.16 Useful balance reports +24.6.16 Useful balance reports ------------------------------ Some frequently used 'balance' options/reports are: @@ -8457,7 +8553,7 @@ Some frequently used 'balance' options/reports are:  File: hledger.info, Node: balancesheet, Next: balancesheetequity, Prev: balance, Up: PART 4 COMMANDS -23.7 balancesheet +24.7 balancesheet ================= (bs) @@ -8500,13 +8596,13 @@ smarter account detection, and liabilities displayed with their sign flipped. This command also supports the output destination and output format -options The output formats supported are 'txt', 'csv', 'html', and -(experimental) 'json'. +options The output formats supported are 'txt', 'csv', 'tsv', 'html', +and (experimental) 'json'.  File: hledger.info, Node: balancesheetequity, Next: cashflow, Prev: balancesheet, Up: PART 4 COMMANDS -23.8 balancesheetequity +24.8 balancesheetequity ======================= (bse) @@ -8554,13 +8650,13 @@ with smarter account detection, and liabilities/equity displayed with their sign flipped. This command also supports the output destination and output format -options The output formats supported are 'txt', 'csv', 'html', and -(experimental) 'json'. +options The output formats supported are 'txt', 'csv', 'tsv', 'html', +and (experimental) 'json'.  File: hledger.info, Node: cashflow, Next: check, Prev: balancesheetequity, Up: PART 4 COMMANDS -23.9 cashflow +24.9 cashflow ============= (cf) @@ -8607,13 +8703,13 @@ It is similar to 'hledger balance assets not:fixed not:investment not:receivable', but with smarter account detection. This command also supports the output destination and output format -options The output formats supported are 'txt', 'csv', 'html', and -(experimental) 'json'. +options The output formats supported are 'txt', 'csv', 'tsv', 'html', +and (experimental) 'json'.  File: hledger.info, Node: check, Next: close, Prev: cashflow, Up: PART 4 COMMANDS -23.10 check +24.10 check =========== Check for various kinds of errors in your data. @@ -8646,7 +8742,7 @@ run these checks, providing instant feedback as you edit the journal.  File: hledger.info, Node: Default checks, Next: Strict checks, Up: check -23.10.1 Default checks +24.10.1 Default checks ---------------------- These checks are run automatically by (almost) all hledger commands: @@ -8664,7 +8760,7 @@ These checks are run automatically by (almost) all hledger commands:  File: hledger.info, Node: Strict checks, Next: Other checks, Prev: Default checks, Up: check -23.10.2 Strict checks +24.10.2 Strict checks --------------------- These additional checks are run when the '-s'/'--strict' (strict mode) @@ -8683,7 +8779,7 @@ flag is used. Or, they can be run by giving their names as arguments to  File: hledger.info, Node: Other checks, Next: Custom checks, Prev: Strict checks, Up: check -23.10.3 Other checks +24.10.3 Other checks -------------------- These checks can be run only by giving their names as arguments to @@ -8703,7 +8799,7 @@ These checks can be run only by giving their names as arguments to  File: hledger.info, Node: Custom checks, Next: More about specific checks, Prev: Other checks, Up: check -23.10.4 Custom checks +24.10.4 Custom checks --------------------- A few more checks are are available as separate add-on commands, in @@ -8721,7 +8817,7 @@ See: Cookbook -> Scripting.  File: hledger.info, Node: More about specific checks, Prev: Custom checks, Up: check -23.10.5 More about specific checks +24.10.5 More about specific checks ---------------------------------- 'hledger check recentassertions' will complain if any balance-asserted @@ -8739,7 +8835,7 @@ balance.)  File: hledger.info, Node: close, Next: codes, Prev: check, Up: PART 4 COMMANDS -23.11 close +24.11 close =========== (equity) @@ -8824,7 +8920,7 @@ the day after the closing date.  File: hledger.info, Node: close and balance assertions, Next: Example retain earnings, Up: close -23.11.1 close and balance assertions +24.11.1 close and balance assertions ------------------------------------ Balance assertions will be generated, verifying that the accounts have @@ -8862,7 +8958,7 @@ single-day transactions:  File: hledger.info, Node: Example retain earnings, Next: Example migrate balances to a new file, Prev: close and balance assertions, Up: close -23.11.2 Example: retain earnings +24.11.2 Example: retain earnings -------------------------------- Record 2022's revenues/expenses as retained earnings on 2022-12-31, @@ -8879,7 +8975,7 @@ $ hledger -f 2022.journal is not:desc:'retain earnings'  File: hledger.info, Node: Example migrate balances to a new file, Next: Example excluding closing/opening transactions, Prev: Example retain earnings, Up: close -23.11.3 Example: migrate balances to a new file +24.11.3 Example: migrate balances to a new file ----------------------------------------------- Close assets/liabilities/equity on 2022-12-31 and re-open them on @@ -8899,7 +8995,7 @@ $ hledger -f 2022.journal bs not:desc:'closing balances'  File: hledger.info, Node: Example excluding closing/opening transactions, Prev: Example migrate balances to a new file, Up: close -23.11.4 Example: excluding closing/opening transactions +24.11.4 Example: excluding closing/opening transactions ------------------------------------------------------- When combining many files for multi-year reports, the closing/opening @@ -8949,7 +9045,7 @@ $ hledger -f all.journal bs -e2023 not:tag:clopen=2023  File: hledger.info, Node: codes, Next: commodities, Prev: close, Up: PART 4 COMMANDS -23.12 codes +24.12 codes =========== List the codes seen in transactions, in the order parsed. @@ -8997,7 +9093,7 @@ $ hledger codes -E  File: hledger.info, Node: commodities, Next: demo, Prev: codes, Up: PART 4 COMMANDS -23.13 commodities +24.13 commodities ================= List all commodity/currency symbols used or declared in the journal. @@ -9005,7 +9101,7 @@ List all commodity/currency symbols used or declared in the journal.  File: hledger.info, Node: demo, Next: descriptions, Prev: commodities, Up: PART 4 COMMANDS -23.14 demo +24.14 demo ========== Play demos of hledger usage in the terminal, if asciinema is installed. @@ -9034,7 +9130,7 @@ $ hledger demo install -s4 # play the "install" demo at 4x speed  File: hledger.info, Node: descriptions, Next: diff, Prev: demo, Up: PART 4 COMMANDS -23.15 descriptions +24.15 descriptions ================== List the unique descriptions that appear in transactions. @@ -9053,7 +9149,7 @@ Person A  File: hledger.info, Node: diff, Next: files, Prev: descriptions, Up: PART 4 COMMANDS -23.16 diff +24.16 diff ========== Compares a particular account's transactions in two input files. It @@ -9087,7 +9183,7 @@ These transactions are in the second file only:  File: hledger.info, Node: files, Next: help, Prev: diff, Up: PART 4 COMMANDS -23.17 files +24.17 files =========== List all files included in the journal. With a REGEX argument, only @@ -9096,7 +9192,7 @@ file names matching the regular expression (case sensitive) are shown.  File: hledger.info, Node: help, Next: import, Prev: files, Up: PART 4 COMMANDS -23.18 help +24.18 help ========== Show the hledger user manual in the terminal, with 'info', 'man', or a @@ -9131,13 +9227,13 @@ $ hledger help -m journal # show it with man, even if info is installed  File: hledger.info, Node: import, Next: incomestatement, Prev: help, Up: PART 4 COMMANDS -23.19 import +24.19 import ============ -Read new transactions added to each FILE since last run, and add them to -the journal. Or with -dry-run, just print the transactions that would -be added. Or with -catchup, just mark all of the FILEs' transactions as -imported, without actually importing any. +Read new transactions added to each FILE provided as arguments since +last run, and add them to the journal. Or with -dry-run, just print the +transactions that would be added. Or with -catchup, just mark all of +the FILEs' current transactions as imported, without importing them. This command may append new transactions to the main journal file (which should be in journal format). Existing transactions are not @@ -9163,17 +9259,17 @@ most common import source, and these docs focus on that case.  File: hledger.info, Node: Deduplication, Next: Import testing, Up: import -23.19.1 Deduplication +24.19.1 Deduplication --------------------- -As a convenience 'import' does _deduplication_ while reading -transactions. This does not mean "ignore transactions that look the -same", but rather "ignore transactions that have been seen before". -This is intended for when you are periodically importing foreign data -which may contain already-imported transactions. So eg, if every day -you download bank CSV files containing redundant data, you can safely -run 'hledger import bank.csv' and only new transactions will be -imported. ('import' is idempotent.) +'import' does _time-based deduplication_, to detect only the new +transactions since the last successful import. (This does not mean +"ignore transactions that look the same", but rather "ignore +transactions that have been seen before".) This is intended for when +you are periodically importing downloaded data, which may overlap with +previous downloads. Eg if every week (or every day) you download a +bank's last three months of CSV data, you can safely run 'hledger import +thebank.csv' each time and only new transactions will be imported. Since the items being read (CSV records, eg) often do not come with unique identifiers, hledger detects new transactions by date, assuming @@ -9191,8 +9287,10 @@ you import often, the new transactions will be few, so less likely to be the ones affected). hledger remembers the latest date processed in each input file by -saving a hidden ".latest" state file in the same directory. Eg when -reading 'finance/bank.csv', it will look for and update the +saving a hidden ".latest.FILE" file in FILE's directory (after a +succesful import). + + Eg when reading 'finance/bank.csv', it will look for and update the 'finance/.latest.bank.csv' state file. The format is simple: one or more lines containing the same ISO-format date (YYYY-MM-DD), meaning "I have processed transactions up to this date, and this many of them on @@ -9209,7 +9307,7 @@ certain date.  File: hledger.info, Node: Import testing, Next: Importing balance assignments, Prev: Deduplication, Up: import -23.19.2 Import testing +24.19.2 Import testing ---------------------- With '--dry-run', the transactions that will be imported are printed to @@ -9234,7 +9332,7 @@ import.  File: hledger.info, Node: Importing balance assignments, Next: Commodity display styles, Prev: Import testing, Up: import -23.19.3 Importing balance assignments +24.19.3 Importing balance assignments ------------------------------------- Entries added by import will have their posting amounts made explicit @@ -9253,7 +9351,7 @@ please test it and send a pull request.)  File: hledger.info, Node: Commodity display styles, Prev: Importing balance assignments, Up: import -23.19.4 Commodity display styles +24.19.4 Commodity display styles -------------------------------- Imported amounts will be formatted according to the canonical commodity @@ -9262,7 +9360,7 @@ styles (declared or inferred) in the main journal file.  File: hledger.info, Node: incomestatement, Next: notes, Prev: import, Up: PART 4 COMMANDS -23.20 incomestatement +24.20 incomestatement ===================== (is) @@ -9306,13 +9404,13 @@ with smarter account detection, and revenues/income displayed with their sign flipped. This command also supports the output destination and output format -options The output formats supported are 'txt', 'csv', 'html', and -(experimental) 'json'. +options The output formats supported are 'txt', 'csv', 'tsv', 'html', +and (experimental) 'json'.  File: hledger.info, Node: notes, Next: payees, Prev: incomestatement, Up: PART 4 COMMANDS -23.21 notes +24.21 notes =========== List the unique notes that appear in transactions. @@ -9331,7 +9429,7 @@ Snacks  File: hledger.info, Node: payees, Next: prices, Prev: notes, Up: PART 4 COMMANDS -23.22 payees +24.22 payees ============ List the unique payee/payer names that appear in transactions. @@ -9356,19 +9454,28 @@ Person A  File: hledger.info, Node: prices, Next: print, Prev: payees, Up: PART 4 COMMANDS -23.23 prices +24.23 prices ============ -Print market price directives from the journal. With --infer-market-prices, generate additional market prices from costs. -With -infer-reverse-prices, also generate market prices by inverting -known prices. Prices can be filtered by a query. Price amounts are -displayed with their full precision. +Print the market prices declared with P directives. With +-infer-market-prices, also show any additional prices inferred from +costs. With -show-reverse, also show additional prices inferred by +reversing known prices. + + Price amounts are always displayed with their full precision, except +for reverse prices which are limited to 8 decimal digits. + + Prices can be filtered by a date:, cur: or amt: query. + + Generally if you run this command with -infer-market-prices +-show-reverse, it will show the same prices used internally to calculate +value reports. But if in doubt, you can inspect those directly by +running the value report with -debug=2.  File: hledger.info, Node: print, Next: register, Prev: prices, Up: PART 4 COMMANDS -23.24 print +24.24 print =========== Show transaction journal entries, sorted by date. @@ -9376,26 +9483,14 @@ Show transaction journal entries, sorted by date. The print command displays full journal entries (transactions) from the journal file, sorted by date (or with '--date2', by secondary date). - Amounts are shown mostly normalised to commodity display style, eg -the placement of commodity symbols will be consistent. All of their -decimal places are shown, as in the original journal entry (with one -alteration: in some cases trailing zeroes are added.) - - Amounts are shown right-aligned within each transaction (but not -across all transactions). - Directives and inter-transaction comments are not shown, currently. This means the print command is somewhat lossy, and if you are using it -to reformat your journal you should take care to also copy over the -directives and file-level comments. +to reformat/regenerate your journal you should take care to also copy +over the directives and inter-transaction comments. Eg: -$ hledger print -2008/01/01 income - assets:bank:checking $1 - income:salary $-1 - +$ hledger print -f examples/sample.journal date:200806 2008/06/01 gift assets:bank:checking $1 income:gifts $-1 @@ -9409,13 +9504,75 @@ $ hledger print expenses:supplies $1 assets:cash $-2 -2008/12/31 * pay off - liabilities:debts $1 - assets:bank:checking $-1 +* Menu: - print's output is usually a valid hledger journal, and you can -process it again with a second hledger command. This can be useful for -certain kinds of search, eg: +* print explicitness:: +* print amount style:: +* print parseability:: +* print other features:: +* print output format:: + + +File: hledger.info, Node: print explicitness, Next: print amount style, Up: print + +24.24.1 print explicitness +-------------------------- + +Normally, whether posting amounts are implicit or explicit is preserved. +For example, when an amount is omitted in the journal, it will not +appear in the output. Similarly, if a conversion cost is implied but +not written, it will not appear in the output. + + You can use the '-x'/'--explicit' flag to force explicit display of +all amounts and costs. This can be useful for troubleshooting or for +making your journal more readable and robust against data entry errors. +'-x' is also implied by using any of '-B','-V','-X','--value'. + + The '-x'/'--explicit' flag will cause any postings with a +multi-commodity amount (which can arise when a multi-commodity +transaction has an implicit amount) to be split into multiple +single-commodity postings, keeping the output parseable. + + +File: hledger.info, Node: print amount style, Next: print parseability, Prev: print explicitness, Up: print + +24.24.2 print amount style +-------------------------- + +Amounts are shown right-aligned within each transaction (but not aligned +across all transactions; you can do that with ledger-mode in Emacs). + + Amounts will be (mostly) normalised to their commodity display style: +their symbol placement, decimal mark, and digit group marks will be made +consistent. By default, decimal digits are shown as they are written in +the journal. + + With the '--round' option, 'print' will try increasingly hard to +display decimal digits according to the commodity display styles: + + * '--round=none' show amounts with original precisions (default) + * '--round=soft' add/remove decimal zeros in amounts (except costs) + * '--round=hard' round amounts (except costs), possibly hiding + significant digits + * '--round=all' round all amounts and costs + + 'soft' is good for non-lossy cleanup, formatting amounts more +consistently where it's safe to do so. + + 'hard' and 'all' can cause 'print' to show invalid unbalanced journal +entries; they may be useful eg for stronger cleanup, with manual fixups +when needed. + + +File: hledger.info, Node: print parseability, Next: print other features, Prev: print amount style, Up: print + +24.24.3 print parseability +-------------------------- + +print's output is usually a valid hledger journal, and you can process +it again with a second hledger command. This can be useful for certain +kinds of search (though the same can be achieved with 'expr:' queries +now): # Show running total of food expenses paid from cash. # -f- reads from stdin. -I/--ignore-assertions is sometimes needed. @@ -9429,36 +9586,47 @@ unparseable: * Auto postings can generate postings with too many missing amounts. * Account aliases can generate bad account names. - Normally, the journal entry's explicit or implicit amount style is -preserved. For example, when an amount is omitted in the journal, it -will not appear in the output. Similarly, when a cost is implied but -not written, it will not appear in the output. You can use the -'-x'/'--explicit' flag to make all amounts and costs explicit, which can -be useful for troubleshooting or for making your journal more readable -and robust against data entry errors. '-x' is also implied by using any -of '-B','-V','-X','--value'. + +File: hledger.info, Node: print other features, Next: print output format, Prev: print parseability, Up: print - Note, '-x'/'--explicit' will cause postings with a multi-commodity -amount (these can arise when a multi-commodity transaction has an -implicit amount) to be split into multiple single-commodity postings, -keeping the output parseable. +24.24.4 print, other features +----------------------------- - With '-B'/'--cost', amounts with costs are converted to cost using -that price. This can be used for troubleshooting. +With '-B'/'--cost', amounts with costs are shown converted to cost. - With '-m DESC'/'--match=DESC', print does a fuzzy search for one -recent transaction whose description is most similar to DESC. DESC -should contain at least two characters. If there is no similar-enough -match, no transaction will be shown and the program exit code will be -non-zero. - - With '--new', hledger prints only transactions it has not seen on a + With '--new', print shows only transactions it has not seen on a previous run. This uses the same deduplication system as the 'import' command. (See import's docs for details.) - This command also supports the output destination and output format -options The output formats supported are 'txt', 'csv', and -(experimental) 'json' and 'sql'. + With '-m DESC'/'--match=DESC', print shows one recent transaction +whose description is most similar to DESC. DESC should contain at least +two characters. If there is no similar-enough match, no transaction +will be shown and the program exit code will be non-zero. + + +File: hledger.info, Node: print output format, Prev: print other features, Up: print + +24.24.5 print output format +--------------------------- + +This command also supports the output destination and output format +options The output formats supported are 'txt', 'beancount', 'csv', +'tsv', 'json' and 'sql'. + + _Experimental:_ The 'beancount' format tries to produce +Beancount-compatible output. It is very basic and may require +additional manual fixups: + + * Transaction and postings with unmarked status are converted to + cleared ('*") status. + * Transactions' payee and or note are wrapped in double quotes. + * Transaction tags are copied to Beancount #tag format. + * Account name parts are capitalised, and if the first account name + part is not one of Assets, Liabilities, Equity, Income, or + Expenses, "Equity:" is prepended. + * The '$' commodity symbol is converted to 'USD'. + * An 'open' directive is generated for each account used, on the + earliest transaction date. Here's an example of print's CSV output: @@ -9492,7 +9660,7 @@ $ hledger print -Ocsv  File: hledger.info, Node: register, Next: rewrite, Prev: print, Up: PART 4 COMMANDS -23.25 register +24.25 register ============== (reg) @@ -9602,7 +9770,7 @@ no posting will be shown and the program exit code will be non-zero.  File: hledger.info, Node: Custom register output, Up: register -23.25.1 Custom register output +24.25.1 Custom register output ------------------------------ register uses the full terminal width by default, except on windows. @@ -9628,13 +9796,13 @@ $ hledger reg -w 100,40 # set overall width 100, description width 40 $ hledger reg -w $COLUMNS,40 # use terminal width, & description width 40 This command also supports the output destination and output format -options The output formats supported are 'txt', 'csv', and +options The output formats supported are 'txt', 'csv', 'tsv', and (experimental) 'json'.  File: hledger.info, Node: rewrite, Next: roi, Prev: register, Up: PART 4 COMMANDS -23.26 rewrite +24.26 rewrite ============= Print all transactions, rewriting the postings of matched transactions. @@ -9687,7 +9855,7 @@ commodity.  File: hledger.info, Node: Re-write rules in a file, Next: Diff output format, Up: rewrite -23.26.1 Re-write rules in a file +24.26.1 Re-write rules in a file -------------------------------- During the run this tool will execute so called "Automated Transactions" @@ -9725,7 +9893,7 @@ postings.  File: hledger.info, Node: Diff output format, Next: rewrite vs print --auto, Prev: Re-write rules in a file, Up: rewrite -23.26.2 Diff output format +24.26.2 Diff output format -------------------------- To use this tool for batch modification of your journal files you may @@ -9766,7 +9934,7 @@ output from 'hledger print'.  File: hledger.info, Node: rewrite vs print --auto, Prev: Diff output format, Up: rewrite -23.26.3 rewrite vs. print -auto +24.26.3 rewrite vs. print -auto ------------------------------- This command predates print -auto, and currently does much the same @@ -9786,7 +9954,7 @@ thing, but with these differences:  File: hledger.info, Node: roi, Next: stats, Prev: rewrite, Up: PART 4 COMMANDS -23.27 roi +24.27 roi ========= Shows the time-weighted (TWR) and money-weighted (IRR) rate of return on @@ -9836,7 +10004,7 @@ annual rate.  File: hledger.info, Node: Spaces and special characters in --inv and --pnl, Next: Semantics of --inv and --pnl, Up: roi -23.27.1 Spaces and special characters in '--inv' and +24.27.1 Spaces and special characters in '--inv' and ---------------------------------------------------- '--pnl' Note that '--inv' and '--pnl''s argument is a query, and queries @@ -9855,7 +10023,7 @@ $ hledger roi --inv="'Assets:Test 1'" --pnl="'Equity:Unrealized Profit and Loss'  File: hledger.info, Node: Semantics of --inv and --pnl, Next: IRR and TWR explained, Prev: Spaces and special characters in --inv and --pnl, Up: roi -23.27.2 Semantics of '--inv' and '--pnl' +24.27.2 Semantics of '--inv' and '--pnl' ---------------------------------------- Query supplied to '--inv' has to match all transactions that are related @@ -9909,7 +10077,7 @@ postings in the example below would be classifed as:  File: hledger.info, Node: IRR and TWR explained, Prev: Semantics of --inv and --pnl, Up: roi -23.27.3 IRR and TWR explained +24.27.3 IRR and TWR explained ----------------------------- "ROI" stands for "return on investment". Traditionally this was @@ -9978,7 +10146,7 @@ cash in-flows and out-flows.  File: hledger.info, Node: stats, Next: tags, Prev: roi, Up: PART 4 COMMANDS -23.28 stats +24.28 stats =========== Show journal and performance statistics. @@ -10018,7 +10186,7 @@ Throughput : 8342 txns/s  File: hledger.info, Node: tags, Next: test, Prev: stats, Up: PART 4 COMMANDS -23.29 tags +24.29 tags ========== List the tags used in the journal, or their values. @@ -10048,7 +10216,7 @@ transactions also acquire tags from their postings.  File: hledger.info, Node: test, Prev: tags, Up: PART 4 COMMANDS -23.30 test +24.30 test ========== Run built-in unit tests. @@ -10074,7 +10242,7 @@ $ hledger test -- -pData.Amount --color=never  File: hledger.info, Node: PART 5 COMMON TASKS, Next: BUGS, Prev: PART 4 COMMANDS, Up: Top -24 PART 5: COMMON TASKS +25 PART 5: COMMON TASKS *********************** Here are some quick examples of how to do some basic tasks with hledger. @@ -10094,7 +10262,7 @@ Here are some quick examples of how to do some basic tasks with hledger.  File: hledger.info, Node: Getting help, Next: Constructing command lines, Up: PART 5 COMMON TASKS -24.1 Getting help +25.1 Getting help ================= Here's how to list commands and view options and command docs: @@ -10117,7 +10285,7 @@ can be found at https://hledger.org/support.  File: hledger.info, Node: Constructing command lines, Next: Starting a journal file, Prev: Getting help, Up: PART 5 COMMON TASKS -24.2 Constructing command lines +25.2 Constructing command lines =============================== hledger has a flexible command line interface. We strive to keep it @@ -10137,7 +10305,7 @@ described in OPTIONS, here are some tips that might help:  File: hledger.info, Node: Starting a journal file, Next: Setting LEDGER_FILE, Prev: Constructing command lines, Up: PART 5 COMMON TASKS -24.3 Starting a journal file +25.3 Starting a journal file ============================ hledger looks for your accounting data in a journal file, @@ -10176,7 +10344,7 @@ Market prices : 0 ()  File: hledger.info, Node: Setting LEDGER_FILE, Next: Setting opening balances, Prev: Starting a journal file, Up: PART 5 COMMON TASKS -24.4 Setting LEDGER_FILE +25.4 Setting LEDGER_FILE ======================== How to set 'LEDGER_FILE' permanently depends on your setup: @@ -10184,7 +10352,7 @@ How to set 'LEDGER_FILE' permanently depends on your setup: On unix and mac, running these commands in the terminal will work for many people; adapt as needed: -$ echo 'export LEDGER_FILE=~/finance/2023.journal` >> ~/.profile +$ echo 'export LEDGER_FILE=~/finance/2023.journal' >> ~/.profile $ source ~/.profile When correctly configured, in a new terminal window 'env | grep @@ -10212,7 +10380,7 @@ persists across a reboot, and if you need to be an Administrator):  File: hledger.info, Node: Setting opening balances, Next: Recording transactions, Prev: Setting LEDGER_FILE, Up: PART 5 COMMON TASKS -24.5 Setting opening balances +25.5 Setting opening balances ============================= Pick a starting date for which you can look up the balances of some @@ -10295,7 +10463,7 @@ $ git commit -m 'initial balances' 2023.journal  File: hledger.info, Node: Recording transactions, Next: Reconciling, Prev: Setting opening balances, Up: PART 5 COMMON TASKS -24.6 Recording transactions +25.6 Recording transactions =========================== As you spend or receive money, you can record these transactions using @@ -10321,7 +10489,7 @@ and hledger.org for more ideas:  File: hledger.info, Node: Reconciling, Next: Reporting, Prev: Recording transactions, Up: PART 5 COMMON TASKS -24.7 Reconciling +25.7 Reconciling ================ Periodically you should reconcile - compare your hledger-reported @@ -10376,7 +10544,7 @@ $ git commit -m 'txns' 2023.journal  File: hledger.info, Node: Reporting, Next: Migrating to a new file, Prev: Reconciling, Up: PART 5 COMMON TASKS -24.8 Reporting +25.8 Reporting ============== Here are some basic reports. @@ -10524,7 +10692,7 @@ $ hledger activity -W  File: hledger.info, Node: Migrating to a new file, Prev: Reporting, Up: PART 5 COMMON TASKS -24.9 Migrating to a new file +25.9 Migrating to a new file ============================ At the end of the year, you may want to continue your journal in a new @@ -10537,7 +10705,7 @@ close command.  File: hledger.info, Node: BUGS, Prev: PART 5 COMMON TASKS, Up: Top -25 BUGS +26 BUGS ******* We welcome bug reports in the hledger issue tracker (shortcut: @@ -10569,7 +10737,7 @@ Ledger.  File: hledger.info, Node: Troubleshooting, Up: BUGS -25.1 Troubleshooting +26.1 Troubleshooting ==================== Here are some common issues you might encounter when you run hledger, @@ -10611,6 +10779,12 @@ locale name may be important: Here's one common way to configure this permanently for your shell: $ echo "export LANG=en_US.utf8" >>~/.profile +# close and re-open terminal window + + If you are using Nix (not NixOS) for GHC and Hledger, you might need +to set the 'LOCALE_ARCHIVE' variable: + +$ echo "export LOCALE_ARCHIVE=${glibcLocales}/lib/locale/locale-archive" >>~/.profile # close and re-open terminal window *COMPATIBILITY ISSUES: hledger gives an error with my Ledger file* @@ -10620,634 +10794,652 @@ See hledger and Ledger for full details.  Tag Table: Node: Top210 -Node: PART 1 USER INTERFACE3788 -Ref: #part-1-user-interface3927 -Node: Input3927 -Ref: #input4037 -Node: Data formats4986 -Ref: #data-formats5099 -Node: Standard input6532 -Ref: #standard-input6672 -Node: Multiple files6899 -Ref: #multiple-files7038 -Node: Strict mode7636 -Ref: #strict-mode7746 -Node: Commands8470 -Ref: #commands8572 -Node: Add-on commands9639 -Ref: #add-on-commands9741 -Node: Options10857 -Ref: #options10969 -Node: General help options11297 -Ref: #general-help-options11443 -Node: General input options11725 -Ref: #general-input-options11907 -Node: General reporting options12609 -Ref: #general-reporting-options12770 -Node: Command line tips16160 -Ref: #command-line-tips16290 -Node: Option repetition16549 -Ref: #option-repetition16693 -Node: Special characters16797 -Ref: #special-characters16970 -Node: Single escaping shell metacharacters17133 -Ref: #single-escaping-shell-metacharacters17374 -Node: Double escaping regular expression metacharacters17977 -Ref: #double-escaping-regular-expression-metacharacters18288 -Node: Triple escaping for add-on commands18814 -Ref: #triple-escaping-for-add-on-commands19074 -Node: Less escaping19718 -Ref: #less-escaping19872 -Node: Unicode characters20196 -Ref: #unicode-characters20371 -Node: Regular expressions21783 -Ref: #regular-expressions21956 -Node: Argument files23700 -Ref: #argument-files23836 -Node: Output24333 -Ref: #output24445 -Node: Output destination24572 -Ref: #output-destination24703 -Node: Output format25128 -Ref: #output-format25274 -Node: CSV output26871 -Ref: #csv-output26987 -Node: HTML output27090 -Ref: #html-output27228 -Node: JSON output27322 -Ref: #json-output27460 -Node: SQL output28382 -Ref: #sql-output28498 -Node: Commodity styles29233 -Ref: #commodity-styles29373 -Node: Colour29972 -Ref: #colour30090 -Node: Box-drawing30494 -Ref: #box-drawing30612 -Node: Paging30902 -Ref: #paging31016 -Node: Debug output31969 -Ref: #debug-output32075 -Node: Environment32738 -Ref: #environment32862 -Node: PART 2 DATA FORMATS33406 -Ref: #part-2-data-formats33549 -Node: Journal33549 -Ref: #journal33658 -Node: Journal cheatsheet34315 -Ref: #journal-cheatsheet34454 -Node: About journal format38439 -Ref: #about-journal-format38599 -Node: Comments40215 -Ref: #comments40345 -Node: Transactions41161 -Ref: #transactions41284 -Node: Dates42298 -Ref: #dates42405 -Node: Simple dates42450 -Ref: #simple-dates42566 -Node: Posting dates43066 -Ref: #posting-dates43184 -Node: Status44153 -Ref: #status44254 -Node: Code45962 -Ref: #code46065 -Node: Description46297 -Ref: #description46428 -Node: Payee and note46748 -Ref: #payee-and-note46854 -Node: Transaction comments47189 -Ref: #transaction-comments47342 -Node: Postings47705 -Ref: #postings47838 -Node: Account names48833 -Ref: #account-names48963 -Node: Amounts50637 -Ref: #amounts50752 -Node: Decimal marks digit group marks51737 -Ref: #decimal-marks-digit-group-marks51912 -Node: Commodity52926 -Ref: #commodity53113 -Node: Directives influencing number parsing and display54065 -Ref: #directives-influencing-number-parsing-and-display54324 -Node: Commodity display style54776 -Ref: #commodity-display-style54982 -Node: Rounding57151 -Ref: #rounding57269 -Node: Costs57568 -Ref: #costs57684 -Node: Other cost/lot notations59880 -Ref: #other-costlot-notations60012 -Node: Balance assertions62601 -Ref: #balance-assertions62752 -Node: Assertions and ordering63835 -Ref: #assertions-and-ordering64024 -Node: Assertions and multiple included files64724 -Ref: #assertions-and-multiple-included-files64984 -Node: Assertions and multiple -f files65484 -Ref: #assertions-and-multiple--f-files65735 -Node: Assertions and commodities66132 -Ref: #assertions-and-commodities66354 -Node: Assertions and prices67534 -Ref: #assertions-and-prices67740 -Node: Assertions and subaccounts68167 -Ref: #assertions-and-subaccounts68388 -Node: Assertions and virtual postings68712 -Ref: #assertions-and-virtual-postings68950 -Node: Assertions and auto postings69082 -Ref: #assertions-and-auto-postings69312 -Node: Assertions and precision69957 -Ref: #assertions-and-precision70139 -Node: Posting comments70406 -Ref: #posting-comments70552 -Node: Tags70929 -Ref: #tags71043 -Node: Tag values72236 -Ref: #tag-values72325 -Node: Directives73084 -Ref: #directives73211 -Node: Directives and multiple files74541 -Ref: #directives-and-multiple-files74719 -Node: Directive effects75486 -Ref: #directive-effects75640 -Node: account directive78653 -Ref: #account-directive78809 -Node: Account comments80207 -Ref: #account-comments80357 -Node: Account subdirectives80865 -Ref: #account-subdirectives81056 -Node: Account error checking81198 -Ref: #account-error-checking81396 -Node: Account display order82585 -Ref: #account-display-order82773 -Node: Account types83874 -Ref: #account-types84015 -Node: alias directive87642 -Ref: #alias-directive87803 -Node: Basic aliases88853 -Ref: #basic-aliases88984 -Node: Regex aliases89728 -Ref: #regex-aliases89885 -Node: Combining aliases90775 -Ref: #combining-aliases90953 -Node: Aliases and multiple files92229 -Ref: #aliases-and-multiple-files92433 -Node: end aliases directive93012 -Ref: #end-aliases-directive93231 -Node: Aliases can generate bad account names93380 -Ref: #aliases-can-generate-bad-account-names93628 -Node: Aliases and account types94213 -Ref: #aliases-and-account-types94405 -Node: commodity directive95101 -Ref: #commodity-directive95275 -Node: Commodity error checking97849 -Ref: #commodity-error-checking97995 -Node: decimal-mark directive98510 -Ref: #decimal-mark-directive98692 -Node: include directive99089 -Ref: #include-directive99253 -Node: P directive100165 -Ref: #p-directive100310 -Node: payee directive101199 -Ref: #payee-directive101348 -Node: tag directive101664 -Ref: #tag-directive101819 -Node: Periodic transactions102287 -Ref: #periodic-transactions102452 -Node: Periodic rule syntax104158 -Ref: #periodic-rule-syntax104336 -Node: Periodic rules and relative dates104981 -Ref: #periodic-rules-and-relative-dates105247 -Node: Two spaces between period expression and description!105758 -Ref: #two-spaces-between-period-expression-and-description106035 -Node: Auto postings106719 -Ref: #auto-postings106867 -Node: Auto postings and multiple files109304 -Ref: #auto-postings-and-multiple-files109468 -Node: Auto postings and dates109869 -Ref: #auto-postings-and-dates110117 -Node: Auto postings and transaction balancing / inferred amounts / balance assertions110292 -Ref: #auto-postings-and-transaction-balancing-inferred-amounts-balance-assertions110648 -Node: Auto posting tags111151 -Ref: #auto-posting-tags111433 -Node: Auto postings on forecast transactions only112069 -Ref: #auto-postings-on-forecast-transactions-only112315 -Node: Other syntax112562 -Ref: #other-syntax112678 -Node: Balance assignments113305 -Ref: #balance-assignments113461 -Node: Balance assignments and prices114834 -Ref: #balance-assignments-and-prices115049 -Node: Balance assignments and multiple files115260 -Ref: #balance-assignments-and-multiple-files115491 -Node: Bracketed posting dates115684 -Ref: #bracketed-posting-dates115868 -Node: D directive116382 -Ref: #d-directive116550 -Node: apply account directive118150 -Ref: #apply-account-directive118330 -Node: Y directive119017 -Ref: #y-directive119177 -Node: Secondary dates120005 -Ref: #secondary-dates120159 -Node: Star comments120973 -Ref: #star-comments121133 -Node: Valuation expressions121665 -Ref: #valuation-expressions121842 -Node: Virtual postings121964 -Ref: #virtual-postings122141 -Node: Other Ledger directives123578 -Ref: #other-ledger-directives123741 -Node: CSV124307 -Ref: #csv124400 -Node: CSV rules cheatsheet126480 -Ref: #csv-rules-cheatsheet126609 -Node: source128407 -Ref: #source128530 -Node: separator129410 -Ref: #separator129523 -Node: skip130063 -Ref: #skip130171 -Node: date-format130715 -Ref: #date-format130836 -Node: timezone131560 -Ref: #timezone131683 -Node: newest-first132688 -Ref: #newest-first132826 -Node: intra-day-reversed133403 -Ref: #intra-day-reversed133557 -Node: decimal-mark134005 -Ref: #decimal-mark134146 -Node: fields list134485 -Ref: #fields-list134624 -Node: Field assignment136295 -Ref: #field-assignment136439 -Node: Field names137466 -Ref: #field-names137597 -Node: date field138800 -Ref: #date-field138918 -Node: date2 field138966 -Ref: #date2-field139107 -Node: status field139163 -Ref: #status-field139306 -Node: code field139355 -Ref: #code-field139500 -Node: description field139545 -Ref: #description-field139705 -Node: comment field139764 -Ref: #comment-field139919 -Node: account field140212 -Ref: #account-field140362 -Node: amount field140932 -Ref: #amount-field141081 -Node: currency field143773 -Ref: #currency-field143926 -Node: balance field144183 -Ref: #balance-field144315 -Node: if block144687 -Ref: #if-block144808 -Node: Matchers146216 -Ref: #matchers146330 -Node: if table147812 -Ref: #if-table147934 -Node: balance-type149356 -Ref: #balance-type149485 -Node: include150185 -Ref: #include150312 -Node: Working with CSV150756 -Ref: #working-with-csv150903 -Node: Rapid feedback151310 -Ref: #rapid-feedback151443 -Node: Valid CSV151895 -Ref: #valid-csv152041 -Node: File Extension152773 -Ref: #file-extension152946 -Node: Reading CSV from standard input153510 -Ref: #reading-csv-from-standard-input153734 -Node: Reading multiple CSV files153898 -Ref: #reading-multiple-csv-files154129 -Node: Reading files specified by rule154370 -Ref: #reading-files-specified-by-rule154598 -Node: Valid transactions155769 -Ref: #valid-transactions155968 -Node: Deduplicating importing156596 -Ref: #deduplicating-importing156791 -Node: Setting amounts157827 -Ref: #setting-amounts157998 -Node: Amount signs160356 -Ref: #amount-signs160526 -Node: Setting currency/commodity161423 -Ref: #setting-currencycommodity161627 -Node: Amount decimal places162801 -Ref: #amount-decimal-places163007 -Node: Referencing other fields163319 -Ref: #referencing-other-fields163532 -Node: How CSV rules are evaluated164429 -Ref: #how-csv-rules-are-evaluated164646 -Node: Well factored rules166099 -Ref: #well-factored-rules166267 -Node: CSV rules examples166591 -Ref: #csv-rules-examples166726 -Node: Bank of Ireland166791 -Ref: #bank-of-ireland166928 -Node: Coinbase168390 -Ref: #coinbase168528 -Node: Amazon169575 -Ref: #amazon169700 -Node: Paypal171419 -Ref: #paypal171527 -Node: Timeclock179171 -Ref: #timeclock179276 -Node: Timedot181454 -Ref: #timedot181577 -Node: PART 3 REPORTING CONCEPTS186446 -Ref: #part-3-reporting-concepts186610 -Node: Time periods186610 -Ref: #time-periods186744 -Node: Report start & end date186862 -Ref: #report-start-end-date187014 -Node: Smart dates188673 -Ref: #smart-dates188826 -Node: Report intervals190694 -Ref: #report-intervals190849 -Node: Date adjustment191267 -Ref: #date-adjustment191427 -Node: Period expressions192278 -Ref: #period-expressions192419 -Node: Period expressions with a report interval194183 -Ref: #period-expressions-with-a-report-interval194417 -Node: More complex report intervals194631 -Ref: #more-complex-report-intervals194876 -Node: Multiple weekday intervals196677 -Ref: #multiple-weekday-intervals196866 -Node: Depth197688 -Ref: #depth197790 -Node: Queries198086 -Ref: #queries198188 -Node: Query types199313 -Ref: #query-types199434 -Node: Combining query terms202770 -Ref: #combining-query-terms202947 -Node: Queries and command options204215 -Ref: #queries-and-command-options204414 -Node: Queries and valuation204663 -Ref: #queries-and-valuation204858 -Node: Querying with account aliases205087 -Ref: #querying-with-account-aliases205298 -Node: Querying with cost or value205428 -Ref: #querying-with-cost-or-value205605 -Node: Pivoting205906 -Ref: #pivoting206020 -Node: Generating data207797 -Ref: #generating-data207929 -Node: Forecasting209512 -Ref: #forecasting209637 -Node: --forecast210168 -Ref: #forecast210299 -Node: Inspecting forecast transactions211345 -Ref: #inspecting-forecast-transactions211547 -Node: Forecast reports212677 -Ref: #forecast-reports212850 -Node: Forecast tags213786 -Ref: #forecast-tags213946 -Node: Forecast period in detail214406 -Ref: #forecast-period-in-detail214600 -Node: Forecast troubleshooting215494 -Ref: #forecast-troubleshooting215662 -Node: Budgeting216565 -Ref: #budgeting216685 -Node: Cost reporting217122 -Ref: #cost-reporting217256 -Node: Recording costs217917 -Ref: #recording-costs218053 -Node: Reporting at cost219644 -Ref: #reporting-at-cost219819 -Node: Equity conversion postings220409 -Ref: #equity-conversion-postings220623 -Node: Inferring equity conversion postings223054 -Ref: #inferring-equity-conversion-postings223317 -Node: Combining costs and equity conversion postings224069 -Ref: #combining-costs-and-equity-conversion-postings224379 -Node: Requirements for detecting equity conversion postings225367 -Ref: #requirements-for-detecting-equity-conversion-postings225689 -Node: Infer cost and equity by default ?226889 -Ref: #infer-cost-and-equity-by-default227118 -Node: Value reporting227326 -Ref: #value-reporting227468 -Node: -V Value228242 -Ref: #v-value228374 -Node: -X Value in specified commodity228569 -Ref: #x-value-in-specified-commodity228770 -Node: Valuation date228919 -Ref: #valuation-date229096 -Node: Finding market price229533 -Ref: #finding-market-price229744 -Node: --infer-market-prices market prices from transactions230914 -Ref: #infer-market-prices-market-prices-from-transactions231196 -Node: Valuation commodity233958 -Ref: #valuation-commodity234177 -Node: Simple valuation examples235390 -Ref: #simple-valuation-examples235594 -Node: --value Flexible valuation236253 -Ref: #value-flexible-valuation236463 -Node: More valuation examples238107 -Ref: #more-valuation-examples238322 -Node: Interaction of valuation and queries240321 -Ref: #interaction-of-valuation-and-queries240568 -Node: Effect of valuation on reports241040 -Ref: #effect-of-valuation-on-reports241243 -Node: PART 4 COMMANDS248940 -Ref: #part-4-commands249089 -Node: Commands overview249468 -Ref: #commands-overview249602 -Node: DATA ENTRY249781 -Ref: #data-entry249905 -Node: DATA CREATION250104 -Ref: #data-creation250258 -Node: DATA MANAGEMENT250376 -Ref: #data-management250541 -Node: REPORTS FINANCIAL250662 -Ref: #reports-financial250837 -Node: REPORTS VERSATILE251142 -Ref: #reports-versatile251315 -Node: REPORTS BASIC251568 -Ref: #reports-basic251720 -Node: HELP252229 -Ref: #help252351 -Node: ADD-ONS252461 -Ref: #add-ons252567 -Node: accounts253146 -Ref: #accounts253279 -Node: activity255166 -Ref: #activity255285 -Node: add255659 -Ref: #add255769 -Node: aregister258580 -Ref: #aregister258701 -Node: aregister and custom posting dates261589 -Ref: #aregister-and-custom-posting-dates261755 -Node: balance262307 -Ref: #balance262433 -Node: balance features263418 -Ref: #balance-features263558 -Node: Simple balance report265517 -Ref: #simple-balance-report265702 -Node: Balance report line format267327 -Ref: #balance-report-line-format267529 -Node: Filtered balance report269687 -Ref: #filtered-balance-report269879 -Node: List or tree mode270206 -Ref: #list-or-tree-mode270374 -Node: Depth limiting271719 -Ref: #depth-limiting271885 -Node: Dropping top-level accounts272486 -Ref: #dropping-top-level-accounts272686 -Node: Showing declared accounts272996 -Ref: #showing-declared-accounts273195 -Node: Sorting by amount273726 -Ref: #sorting-by-amount273893 -Node: Percentages274563 -Ref: #percentages274722 -Node: Multi-period balance report275270 -Ref: #multi-period-balance-report275470 -Node: Balance change end balance277745 -Ref: #balance-change-end-balance277954 -Node: Balance report types279382 -Ref: #balance-report-types279563 -Node: Calculation type280061 -Ref: #calculation-type280216 -Node: Accumulation type280765 -Ref: #accumulation-type280945 -Node: Valuation type281847 -Ref: #valuation-type282035 -Node: Combining balance report types283036 -Ref: #combining-balance-report-types283230 -Node: Budget report285068 -Ref: #budget-report285230 -Node: Budget report start date290884 -Ref: #budget-report-start-date291062 -Node: Budgets and subaccounts292394 -Ref: #budgets-and-subaccounts292601 -Node: Selecting budget goals296041 -Ref: #selecting-budget-goals296240 -Node: Budget vs forecast297275 -Ref: #budget-vs-forecast297434 -Node: Balance report layout299064 -Ref: #balance-report-layout299244 -Node: Useful balance reports307429 -Ref: #useful-balance-reports307589 -Node: balancesheet308674 -Ref: #balancesheet308819 -Node: balancesheetequity310139 -Ref: #balancesheetequity310297 -Node: cashflow311686 -Ref: #cashflow311817 -Node: check313245 -Ref: #check313359 -Node: Default checks314163 -Ref: #default-checks314289 -Node: Strict checks314786 -Ref: #strict-checks314931 -Node: Other checks315411 -Ref: #other-checks315553 -Node: Custom checks316086 -Ref: #custom-checks316243 -Node: More about specific checks316660 -Ref: #more-about-specific-checks316822 -Node: close317528 -Ref: #close317639 -Node: close and balance assertions321104 -Ref: #close-and-balance-assertions321282 -Node: Example retain earnings322433 -Ref: #example-retain-earnings322650 -Node: Example migrate balances to a new file323082 -Ref: #example-migrate-balances-to-a-new-file323347 -Node: Example excluding closing/opening transactions323923 -Ref: #example-excluding-closingopening-transactions324172 -Node: codes325390 -Ref: #codes325507 -Node: commodities326371 -Ref: #commodities326499 -Node: demo326569 -Ref: #demo326690 -Node: descriptions327606 -Ref: #descriptions327736 -Node: diff328027 -Ref: #diff328142 -Node: files329184 -Ref: #files329293 -Node: help329434 -Ref: #help-1329543 -Node: import330916 -Ref: #import331039 -Node: Deduplication332125 -Ref: #deduplication332250 -Node: Import testing334208 -Ref: #import-testing334373 -Node: Importing balance assignments335216 -Ref: #importing-balance-assignments335422 -Node: Commodity display styles336071 -Ref: #commodity-display-styles336244 -Node: incomestatement336373 -Ref: #incomestatement336515 -Node: notes337836 -Ref: #notes337958 -Node: payees338320 -Ref: #payees338435 -Node: prices338954 -Ref: #prices339069 -Node: print339367 -Ref: #print339482 -Node: register344826 -Ref: #register344948 -Node: Custom register output349979 -Ref: #custom-register-output350110 -Node: rewrite351447 -Ref: #rewrite351565 -Node: Re-write rules in a file353463 -Ref: #re-write-rules-in-a-file353626 -Node: Diff output format354775 -Ref: #diff-output-format354958 -Node: rewrite vs print --auto356050 -Ref: #rewrite-vs.-print---auto356210 -Node: roi356766 -Ref: #roi356873 -Node: Spaces and special characters in --inv and --pnl358685 -Ref: #spaces-and-special-characters-in---inv-and---pnl358925 -Node: Semantics of --inv and --pnl359413 -Ref: #semantics-of---inv-and---pnl359652 -Node: IRR and TWR explained361502 -Ref: #irr-and-twr-explained361662 -Node: stats364915 -Ref: #stats365023 -Node: tags366410 -Ref: #tags-1366517 -Node: test367526 -Ref: #test367619 -Node: PART 5 COMMON TASKS368361 -Ref: #part-5-common-tasks368507 -Node: Getting help368805 -Ref: #getting-help368946 -Node: Constructing command lines369706 -Ref: #constructing-command-lines369907 -Node: Starting a journal file370564 -Ref: #starting-a-journal-file370766 -Node: Setting LEDGER_FILE371968 -Ref: #setting-ledger_file372160 -Node: Setting opening balances373117 -Ref: #setting-opening-balances373318 -Node: Recording transactions376459 -Ref: #recording-transactions376648 -Node: Reconciling377204 -Ref: #reconciling377356 -Node: Reporting379613 -Ref: #reporting379762 -Node: Migrating to a new file383747 -Ref: #migrating-to-a-new-file383904 -Node: BUGS384203 -Ref: #bugs384293 -Node: Troubleshooting385172 -Ref: #troubleshooting385272 +Node: PART 1 USER INTERFACE3823 +Ref: #part-1-user-interface3962 +Node: Input3962 +Ref: #input4072 +Node: Data formats5021 +Ref: #data-formats5134 +Node: Standard input6496 +Ref: #standard-input6636 +Node: Multiple files6863 +Ref: #multiple-files7002 +Node: Strict mode7600 +Ref: #strict-mode7710 +Node: Commands8434 +Ref: #commands8536 +Node: Add-on commands9603 +Ref: #add-on-commands9705 +Node: Options10821 +Ref: #options10933 +Node: General help options11261 +Ref: #general-help-options11407 +Node: General input options11689 +Ref: #general-input-options11871 +Node: General reporting options12573 +Ref: #general-reporting-options12734 +Node: Command line tips16124 +Ref: #command-line-tips16254 +Node: Option repetition16513 +Ref: #option-repetition16657 +Node: Special characters16761 +Ref: #special-characters16934 +Node: Single escaping shell metacharacters17097 +Ref: #single-escaping-shell-metacharacters17338 +Node: Double escaping regular expression metacharacters17941 +Ref: #double-escaping-regular-expression-metacharacters18252 +Node: Triple escaping for add-on commands18778 +Ref: #triple-escaping-for-add-on-commands19038 +Node: Less escaping19682 +Ref: #less-escaping19836 +Node: Unicode characters20160 +Ref: #unicode-characters20335 +Node: Regular expressions21747 +Ref: #regular-expressions21920 +Node: hledger's regular expressions25016 +Ref: #hledgers-regular-expressions25175 +Node: Argument files26561 +Ref: #argument-files26697 +Node: Output27194 +Ref: #output27306 +Node: Output destination27433 +Ref: #output-destination27564 +Node: Output format27989 +Ref: #output-format28135 +Node: CSV output29732 +Ref: #csv-output29848 +Node: HTML output29951 +Ref: #html-output30089 +Node: JSON output30183 +Ref: #json-output30321 +Node: SQL output31243 +Ref: #sql-output31359 +Node: Commodity styles32094 +Ref: #commodity-styles32234 +Node: Colour32833 +Ref: #colour32951 +Node: Box-drawing33355 +Ref: #box-drawing33473 +Node: Paging33763 +Ref: #paging33877 +Node: Debug output34830 +Ref: #debug-output34936 +Node: Environment35599 +Ref: #environment35723 +Node: PART 2 DATA FORMATS36267 +Ref: #part-2-data-formats36410 +Node: Journal36410 +Ref: #journal36519 +Node: Journal cheatsheet37176 +Ref: #journal-cheatsheet37315 +Node: About journal format41300 +Ref: #about-journal-format41460 +Node: Comments43076 +Ref: #comments43206 +Node: Transactions44022 +Ref: #transactions44145 +Node: Dates45159 +Ref: #dates45266 +Node: Simple dates45311 +Ref: #simple-dates45427 +Node: Posting dates45927 +Ref: #posting-dates46045 +Node: Status47014 +Ref: #status47115 +Node: Code48823 +Ref: #code48926 +Node: Description49158 +Ref: #description49289 +Node: Payee and note49609 +Ref: #payee-and-note49715 +Node: Transaction comments50050 +Ref: #transaction-comments50203 +Node: Postings50566 +Ref: #postings50699 +Node: Account names51694 +Ref: #account-names51824 +Node: Amounts53498 +Ref: #amounts53613 +Node: Decimal marks digit group marks54598 +Ref: #decimal-marks-digit-group-marks54773 +Node: Commodity55632 +Ref: #commodity55819 +Node: Directives influencing number parsing and display56771 +Ref: #directives-influencing-number-parsing-and-display57030 +Node: Commodity display style57482 +Ref: #commodity-display-style57688 +Node: Rounding59098 +Ref: #rounding59216 +Node: Costs59666 +Ref: #costs59782 +Node: Other cost/lot notations61978 +Ref: #other-costlot-notations62110 +Node: Balance assertions64699 +Ref: #balance-assertions64850 +Node: Assertions and ordering65933 +Ref: #assertions-and-ordering66122 +Node: Assertions and multiple included files66822 +Ref: #assertions-and-multiple-included-files67082 +Node: Assertions and multiple -f files67582 +Ref: #assertions-and-multiple--f-files67833 +Node: Assertions and commodities68230 +Ref: #assertions-and-commodities68452 +Node: Assertions and prices69632 +Ref: #assertions-and-prices69838 +Node: Assertions and subaccounts70265 +Ref: #assertions-and-subaccounts70486 +Node: Assertions and virtual postings70810 +Ref: #assertions-and-virtual-postings71048 +Node: Assertions and auto postings71180 +Ref: #assertions-and-auto-postings71410 +Node: Assertions and precision72055 +Ref: #assertions-and-precision72237 +Node: Posting comments72504 +Ref: #posting-comments72650 +Node: Tags73027 +Ref: #tags73141 +Node: Tag values74334 +Ref: #tag-values74423 +Node: Directives75182 +Ref: #directives75309 +Node: Directives and multiple files76639 +Ref: #directives-and-multiple-files76817 +Node: Directive effects77584 +Ref: #directive-effects77738 +Node: account directive80751 +Ref: #account-directive80907 +Node: Account comments82305 +Ref: #account-comments82455 +Node: Account subdirectives82963 +Ref: #account-subdirectives83154 +Node: Account error checking83296 +Ref: #account-error-checking83494 +Node: Account display order84683 +Ref: #account-display-order84871 +Node: Account types85972 +Ref: #account-types86113 +Node: alias directive89740 +Ref: #alias-directive89901 +Node: Basic aliases90951 +Ref: #basic-aliases91082 +Node: Regex aliases91826 +Ref: #regex-aliases91983 +Node: Combining aliases92873 +Ref: #combining-aliases93051 +Node: Aliases and multiple files94327 +Ref: #aliases-and-multiple-files94531 +Node: end aliases directive95110 +Ref: #end-aliases-directive95329 +Node: Aliases can generate bad account names95478 +Ref: #aliases-can-generate-bad-account-names95726 +Node: Aliases and account types96311 +Ref: #aliases-and-account-types96503 +Node: commodity directive97199 +Ref: #commodity-directive97373 +Node: Commodity directive syntax98558 +Ref: #commodity-directive-syntax98743 +Node: Commodity error checking100122 +Ref: #commodity-error-checking100303 +Node: decimal-mark directive100597 +Ref: #decimal-mark-directive100779 +Node: include directive101176 +Ref: #include-directive101340 +Node: P directive102252 +Ref: #p-directive102397 +Node: payee directive103286 +Ref: #payee-directive103435 +Node: tag directive103751 +Ref: #tag-directive103906 +Node: Periodic transactions104374 +Ref: #periodic-transactions104539 +Node: Periodic rule syntax106245 +Ref: #periodic-rule-syntax106423 +Node: Periodic rules and relative dates107068 +Ref: #periodic-rules-and-relative-dates107334 +Node: Two spaces between period expression and description!107845 +Ref: #two-spaces-between-period-expression-and-description108122 +Node: Auto postings108806 +Ref: #auto-postings108954 +Node: Auto postings and multiple files111391 +Ref: #auto-postings-and-multiple-files111555 +Node: Auto postings and dates111956 +Ref: #auto-postings-and-dates112204 +Node: Auto postings and transaction balancing / inferred amounts / balance assertions112379 +Ref: #auto-postings-and-transaction-balancing-inferred-amounts-balance-assertions112735 +Node: Auto posting tags113238 +Ref: #auto-posting-tags113520 +Node: Auto postings on forecast transactions only114156 +Ref: #auto-postings-on-forecast-transactions-only114402 +Node: Other syntax114649 +Ref: #other-syntax114765 +Node: Balance assignments115392 +Ref: #balance-assignments115548 +Node: Balance assignments and prices116921 +Ref: #balance-assignments-and-prices117136 +Node: Balance assignments and multiple files117347 +Ref: #balance-assignments-and-multiple-files117578 +Node: Bracketed posting dates117771 +Ref: #bracketed-posting-dates117955 +Node: D directive118469 +Ref: #d-directive118637 +Node: apply account directive120237 +Ref: #apply-account-directive120417 +Node: Y directive121104 +Ref: #y-directive121264 +Node: Secondary dates122092 +Ref: #secondary-dates122246 +Node: Star comments123060 +Ref: #star-comments123220 +Node: Valuation expressions123752 +Ref: #valuation-expressions123929 +Node: Virtual postings124051 +Ref: #virtual-postings124228 +Node: Other Ledger directives125665 +Ref: #other-ledger-directives125828 +Node: CSV126394 +Ref: #csv126487 +Node: CSV rules cheatsheet128567 +Ref: #csv-rules-cheatsheet128696 +Node: source130494 +Ref: #source130617 +Node: separator131497 +Ref: #separator131610 +Node: skip132150 +Ref: #skip132258 +Node: date-format132802 +Ref: #date-format132923 +Node: timezone133647 +Ref: #timezone133770 +Node: newest-first134775 +Ref: #newest-first134913 +Node: intra-day-reversed135490 +Ref: #intra-day-reversed135644 +Node: decimal-mark136092 +Ref: #decimal-mark136233 +Node: fields list136572 +Ref: #fields-list136711 +Node: Field assignment138382 +Ref: #field-assignment138526 +Node: Field names139603 +Ref: #field-names139734 +Node: date field140937 +Ref: #date-field141055 +Node: date2 field141103 +Ref: #date2-field141244 +Node: status field141300 +Ref: #status-field141443 +Node: code field141492 +Ref: #code-field141637 +Node: description field141682 +Ref: #description-field141842 +Node: comment field141901 +Ref: #comment-field142056 +Node: account field142349 +Ref: #account-field142499 +Node: amount field143069 +Ref: #amount-field143218 +Node: currency field145910 +Ref: #currency-field146063 +Node: balance field146320 +Ref: #balance-field146452 +Node: if block146824 +Ref: #if-block146945 +Node: Matchers148353 +Ref: #matchers148467 +Node: Match groups150051 +Ref: #match-groups150152 +Node: if table150899 +Ref: #if-table151021 +Node: balance-type152583 +Ref: #balance-type152712 +Node: include153412 +Ref: #include153539 +Node: Working with CSV153983 +Ref: #working-with-csv154130 +Node: Rapid feedback154537 +Ref: #rapid-feedback154670 +Node: Valid CSV155122 +Ref: #valid-csv155268 +Node: File Extension156000 +Ref: #file-extension156173 +Node: Reading CSV from standard input156737 +Ref: #reading-csv-from-standard-input156961 +Node: Reading multiple CSV files157125 +Ref: #reading-multiple-csv-files157356 +Node: Reading files specified by rule157597 +Ref: #reading-files-specified-by-rule157825 +Node: Valid transactions158996 +Ref: #valid-transactions159195 +Node: Deduplicating importing159823 +Ref: #deduplicating-importing160018 +Node: Setting amounts161054 +Ref: #setting-amounts161225 +Node: Amount signs163583 +Ref: #amount-signs163753 +Node: Setting currency/commodity164650 +Ref: #setting-currencycommodity164854 +Node: Amount decimal places166028 +Ref: #amount-decimal-places166234 +Node: Referencing other fields166546 +Ref: #referencing-other-fields166759 +Node: How CSV rules are evaluated167656 +Ref: #how-csv-rules-are-evaluated167873 +Node: Well factored rules169326 +Ref: #well-factored-rules169494 +Node: CSV rules examples169818 +Ref: #csv-rules-examples169953 +Node: Bank of Ireland170018 +Ref: #bank-of-ireland170155 +Node: Coinbase171617 +Ref: #coinbase171755 +Node: Amazon172802 +Ref: #amazon172927 +Node: Paypal174646 +Ref: #paypal174754 +Node: Timeclock182398 +Ref: #timeclock182503 +Node: Timedot184681 +Ref: #timedot184804 +Node: PART 3 REPORTING CONCEPTS189673 +Ref: #part-3-reporting-concepts189855 +Node: Amount formatting parseability189855 +Ref: #amount-formatting-parseability190052 +Node: Time periods191756 +Ref: #time-periods191895 +Node: Report start & end date192013 +Ref: #report-start-end-date192165 +Node: Smart dates193824 +Ref: #smart-dates193977 +Node: Report intervals195845 +Ref: #report-intervals196000 +Node: Date adjustment196418 +Ref: #date-adjustment196578 +Node: Period expressions197429 +Ref: #period-expressions197570 +Node: Period expressions with a report interval199334 +Ref: #period-expressions-with-a-report-interval199568 +Node: More complex report intervals199782 +Ref: #more-complex-report-intervals200027 +Node: Multiple weekday intervals201828 +Ref: #multiple-weekday-intervals202017 +Node: Depth202839 +Ref: #depth202941 +Node: Queries203237 +Ref: #queries203339 +Node: Query types204464 +Ref: #query-types204585 +Node: Combining query terms207921 +Ref: #combining-query-terms208098 +Node: Queries and command options209366 +Ref: #queries-and-command-options209565 +Node: Queries and valuation209814 +Ref: #queries-and-valuation210009 +Node: Querying with account aliases210238 +Ref: #querying-with-account-aliases210449 +Node: Querying with cost or value210579 +Ref: #querying-with-cost-or-value210756 +Node: Pivoting211057 +Ref: #pivoting211171 +Node: Generating data212948 +Ref: #generating-data213080 +Node: Forecasting214663 +Ref: #forecasting214788 +Node: --forecast215319 +Ref: #forecast215450 +Node: Inspecting forecast transactions216496 +Ref: #inspecting-forecast-transactions216698 +Node: Forecast reports217828 +Ref: #forecast-reports218001 +Node: Forecast tags218937 +Ref: #forecast-tags219097 +Node: Forecast period in detail219557 +Ref: #forecast-period-in-detail219751 +Node: Forecast troubleshooting220645 +Ref: #forecast-troubleshooting220813 +Node: Budgeting221716 +Ref: #budgeting221836 +Node: Cost reporting222273 +Ref: #cost-reporting222407 +Node: Recording costs223068 +Ref: #recording-costs223204 +Node: Reporting at cost224795 +Ref: #reporting-at-cost224970 +Node: Equity conversion postings225560 +Ref: #equity-conversion-postings225774 +Node: Inferring equity conversion postings228205 +Ref: #inferring-equity-conversion-postings228468 +Node: Combining costs and equity conversion postings229220 +Ref: #combining-costs-and-equity-conversion-postings229530 +Node: Requirements for detecting equity conversion postings230518 +Ref: #requirements-for-detecting-equity-conversion-postings230840 +Node: Infer cost and equity by default ?232040 +Ref: #infer-cost-and-equity-by-default232269 +Node: Value reporting232477 +Ref: #value-reporting232619 +Node: -V Value233393 +Ref: #v-value233525 +Node: -X Value in specified commodity233720 +Ref: #x-value-in-specified-commodity233921 +Node: Valuation date234070 +Ref: #valuation-date234247 +Node: Finding market price235030 +Ref: #finding-market-price235241 +Node: --infer-market-prices market prices from transactions236410 +Ref: #infer-market-prices-market-prices-from-transactions236692 +Node: Valuation commodity239454 +Ref: #valuation-commodity239673 +Node: Simple valuation examples240886 +Ref: #simple-valuation-examples241090 +Node: --value Flexible valuation241749 +Ref: #value-flexible-valuation241959 +Node: More valuation examples243603 +Ref: #more-valuation-examples243818 +Node: Interaction of valuation and queries245088 +Ref: #interaction-of-valuation-and-queries245335 +Node: Effect of valuation on reports245807 +Ref: #effect-of-valuation-on-reports246010 +Node: PART 4 COMMANDS253707 +Ref: #part-4-commands253856 +Node: Commands overview254235 +Ref: #commands-overview254369 +Node: DATA ENTRY254548 +Ref: #data-entry254672 +Node: DATA CREATION254871 +Ref: #data-creation255025 +Node: DATA MANAGEMENT255143 +Ref: #data-management255308 +Node: REPORTS FINANCIAL255429 +Ref: #reports-financial255604 +Node: REPORTS VERSATILE255909 +Ref: #reports-versatile256082 +Node: REPORTS BASIC256335 +Ref: #reports-basic256487 +Node: HELP256996 +Ref: #help257118 +Node: ADD-ONS257228 +Ref: #add-ons257334 +Node: accounts257913 +Ref: #accounts258046 +Node: activity259933 +Ref: #activity260052 +Node: add260426 +Ref: #add260536 +Node: aregister263347 +Ref: #aregister263468 +Node: aregister and posting dates266356 +Ref: #aregister-and-posting-dates266501 +Node: balance267257 +Ref: #balance267383 +Node: balance features268368 +Ref: #balance-features268508 +Node: Simple balance report270474 +Ref: #simple-balance-report270659 +Node: Balance report line format272284 +Ref: #balance-report-line-format272486 +Node: Filtered balance report274644 +Ref: #filtered-balance-report274836 +Node: List or tree mode275163 +Ref: #list-or-tree-mode275331 +Node: Depth limiting276676 +Ref: #depth-limiting276842 +Node: Dropping top-level accounts277443 +Ref: #dropping-top-level-accounts277643 +Node: Showing declared accounts277953 +Ref: #showing-declared-accounts278152 +Node: Sorting by amount278683 +Ref: #sorting-by-amount278850 +Node: Percentages279520 +Ref: #percentages279679 +Node: Multi-period balance report280227 +Ref: #multi-period-balance-report280427 +Node: Balance change end balance282702 +Ref: #balance-change-end-balance282911 +Node: Balance report types284339 +Ref: #balance-report-types284520 +Node: Calculation type285018 +Ref: #calculation-type285173 +Node: Accumulation type285722 +Ref: #accumulation-type285902 +Node: Valuation type286804 +Ref: #valuation-type286992 +Node: Combining balance report types287993 +Ref: #combining-balance-report-types288187 +Node: Budget report290025 +Ref: #budget-report290187 +Node: Budget report start date295841 +Ref: #budget-report-start-date296019 +Node: Budgets and subaccounts297351 +Ref: #budgets-and-subaccounts297558 +Node: Selecting budget goals300998 +Ref: #selecting-budget-goals301197 +Node: Budget vs forecast302232 +Ref: #budget-vs-forecast302391 +Node: Balance report layout304021 +Ref: #balance-report-layout304201 +Node: Useful balance reports312386 +Ref: #useful-balance-reports312546 +Node: balancesheet313631 +Ref: #balancesheet313776 +Node: balancesheetequity315103 +Ref: #balancesheetequity315261 +Node: cashflow316657 +Ref: #cashflow316788 +Node: check318223 +Ref: #check318337 +Node: Default checks319141 +Ref: #default-checks319267 +Node: Strict checks319764 +Ref: #strict-checks319909 +Node: Other checks320389 +Ref: #other-checks320531 +Node: Custom checks321064 +Ref: #custom-checks321221 +Node: More about specific checks321638 +Ref: #more-about-specific-checks321800 +Node: close322506 +Ref: #close322617 +Node: close and balance assertions326082 +Ref: #close-and-balance-assertions326260 +Node: Example retain earnings327411 +Ref: #example-retain-earnings327628 +Node: Example migrate balances to a new file328060 +Ref: #example-migrate-balances-to-a-new-file328325 +Node: Example excluding closing/opening transactions328901 +Ref: #example-excluding-closingopening-transactions329150 +Node: codes330368 +Ref: #codes330485 +Node: commodities331349 +Ref: #commodities331477 +Node: demo331547 +Ref: #demo331668 +Node: descriptions332584 +Ref: #descriptions332714 +Node: diff333005 +Ref: #diff333120 +Node: files334162 +Ref: #files334271 +Node: help334412 +Ref: #help-1334521 +Node: import335894 +Ref: #import336017 +Node: Deduplication337125 +Ref: #deduplication337250 +Node: Import testing339269 +Ref: #import-testing339434 +Node: Importing balance assignments340277 +Ref: #importing-balance-assignments340483 +Node: Commodity display styles341132 +Ref: #commodity-display-styles341305 +Node: incomestatement341434 +Ref: #incomestatement341576 +Node: notes342904 +Ref: #notes343026 +Node: payees343388 +Ref: #payees343503 +Node: prices344022 +Ref: #prices344137 +Node: print344790 +Ref: #print344905 +Node: print explicitness345881 +Ref: #print-explicitness346024 +Node: print amount style346803 +Ref: #print-amount-style346973 +Node: print parseability348025 +Ref: #print-parseability348197 +Node: print other features348946 +Ref: #print-other-features349125 +Node: print output format349646 +Ref: #print-output-format349794 +Node: register352438 +Ref: #register352560 +Node: Custom register output357591 +Ref: #custom-register-output357722 +Node: rewrite359066 +Ref: #rewrite359184 +Node: Re-write rules in a file361082 +Ref: #re-write-rules-in-a-file361245 +Node: Diff output format362394 +Ref: #diff-output-format362577 +Node: rewrite vs print --auto363669 +Ref: #rewrite-vs.-print---auto363829 +Node: roi364385 +Ref: #roi364492 +Node: Spaces and special characters in --inv and --pnl366304 +Ref: #spaces-and-special-characters-in---inv-and---pnl366544 +Node: Semantics of --inv and --pnl367032 +Ref: #semantics-of---inv-and---pnl367271 +Node: IRR and TWR explained369121 +Ref: #irr-and-twr-explained369281 +Node: stats372534 +Ref: #stats372642 +Node: tags374029 +Ref: #tags-1374136 +Node: test375145 +Ref: #test375238 +Node: PART 5 COMMON TASKS375980 +Ref: #part-5-common-tasks376126 +Node: Getting help376424 +Ref: #getting-help376565 +Node: Constructing command lines377325 +Ref: #constructing-command-lines377526 +Node: Starting a journal file378183 +Ref: #starting-a-journal-file378385 +Node: Setting LEDGER_FILE379587 +Ref: #setting-ledger_file379779 +Node: Setting opening balances380736 +Ref: #setting-opening-balances380937 +Node: Recording transactions384078 +Ref: #recording-transactions384267 +Node: Reconciling384823 +Ref: #reconciling384975 +Node: Reporting387232 +Ref: #reporting387381 +Node: Migrating to a new file391366 +Ref: #migrating-to-a-new-file391523 +Node: BUGS391822 +Ref: #bugs391912 +Node: Troubleshooting392791 +Ref: #troubleshooting392891  End Tag Table diff --git a/hledger/hledger.txt b/hledger/hledger.txt index ce7382c9c..9cce2457a 100644 --- a/hledger/hledger.txt +++ b/hledger/hledger.txt @@ -97,18 +97,17 @@ Input Usually the data file is in hledger's journal format, but it can be in any of the supported file formats, which currently are: - Reader: Reads: Used for file exten- - sions: + Reader: Reads: Used for file extensions: ----------------------------------------------------------------------------- - journal hledger journal files and some Ledger .journal .j .hledger - journals, for transactions .ledger - time- timeclock files, for precise time log- .timeclock - clock ging - timedot timedot files, for approximate time .timedot - logging - csv CSV/SSV/TSV/character-separated values, .csv .ssv .tsv - for data import .csv.rules .ssv.rules - .tsv.rules + journal hledger journal files and some .journal .j .hledger .ledger + Ledger journals, for transac- + tions + timeclock timeclock files, for precise .timeclock + time logging + timedot timedot files, for approximate .timedot + time logging + csv CSV/SSV/TSV/character-sepa- .csv .ssv .tsv .csv.rules + rated values, for data import .ssv.rules .tsv.rules These formats are described in more detail below. @@ -494,33 +493,88 @@ Command line tips and vice versa. (See eg #961). Regular expressions - hledger uses regular expressions in a number of places: + A regular expression (regexp) is a small piece of text where certain + characters (like ., ^, $, +, *, (), |, [], \) have special meanings, + forming a tiny language for matching text precisely - very useful in + hledger and elsewhere. To learn all about them, visit regular-expres- + sions.info. - o query terms, on the command line and in the hledger-web search form: - REGEX, desc:REGEX, cur:REGEX, tag:...=REGEX + hledger supports regexps whenever you are entering a pattern to match + something, eg in query arguments, account aliases, CSV if rules, + hledger-web's search form, hledger-ui's / search, etc. You may need to + wrap them in quotes, especially at the command line (see Special char- + acters above). Here are some examples: - o CSV rules conditional blocks: if REGEX ... + Account name queries (quoted for command line use): - o account alias directive and --alias option: alias /REGEX/ = REPLACE- - MENT, --alias /REGEX/=REPLACEMENT + Regular expression: Matches: + ------------------- ------------------------------------------------------------ + bank assets:bank, assets:bank:savings, expenses:art:banksy, ... + :bank assets:bank:savings, expenses:art:banksy + :bank: assets:bank:savings + '^bank' none of those ( ^ matches beginning of text ) + 'bank$' assets:bank ( $ matches end of text ) + 'big \$ bank' big $ bank ( \ disables following character's special meaning ) + '\bbank\b' assets:bank, assets:bank:savings ( \b matches word boundaries ) + '(sav|check)ing' saving or checking ( (|) matches either alternative ) + 'saving|checking' saving or checking ( outer parentheses are not needed ) + 'savings?' saving or savings ( ? matches 0 or 1 of the preceding thing ) + 'my +bank' my bank, my bank, ... ( + matches 1 or more of the preceding thing ) + 'my *bank' mybank, my bank, my bank, ... ( * matches 0 or more of the preceding thing ) + 'b.nk' bank, bonk, b nk, ... ( . matches any character ) - hledger's regular expressions come from the regex-tdfa library. If - they're not doing what you expect, it's important to know exactly what + Some other queries: + + desc:'amazon|amzn|audible' Amazon transactions + cur:EUR amounts with commodity symbol containing EUR + cur:'\$' amounts with commodity symbol containing $ + cur:'^\$$' only $ amounts, not eg AU$ or CA$ + cur:....? amounts with 4-or-more-character symbols + tag:.=202[1-3] things with any tag whose value contains 2021, 2022 or 2023 + + Account name aliases: accept . instead of : as account separator: + + alias /\./=: replaces all periods in account names with colons + + Show multiple top-level accounts combined as one: + + --alias='/^[^:]+/=combined' ( [^:] matches any character other than : ) + + Show accounts with the second-level part removed: + + --alias '/^([^:]+):[^:]+/ = \1' + match a top-level account and a second-level account + and replace those with just the top-level account + ( \1 in the replacement text means "whatever was matched + by the first parenthesised part of the regexp" + + CSV rules: match CSV records containing dining-related MCC codes: + + if \?MCC581[124] + + Match CSV records with a specific amount around the end/start of month: + + if %amount \b3\.99 + & %date (29|30|31|01|02|03)$ + + hledger's regular expressions + hledger's regular expressions come from the regex-tdfa library. If + they're not doing what you expect, it's important to know exactly what they support: 1. they are case insensitive - 2. they are infix matching (they do not need to match the entire thing + 2. they are infix matching (they do not need to match the entire thing being matched) 3. they are POSIX ERE (extended regular expressions) 4. they also support GNU word boundaries (\b, \B, \<, \>) - 5. they do not support backreferences; if you write \1, it will match - the digit 1. Except when doing text replacement, eg in account - aliases, where backreferences can be used in the replacement string - to reference capturing groups in the search regexp. + 5. backreferences are supported when doing text replacement in account + aliases or CSV rules, where backreferences can be used in the re- + placement string to reference capturing groups in the search regexp. + Otherwise, if you write \1, it will match the digit 1. 6. they do not support mode modifiers ((?s)), character classes (\w, \d), or anything else not mentioned above. @@ -568,7 +622,7 @@ Output Some commands offer other kinds of output, not just text on the termi- nal. Here are those commands and the formats currently supported: - - txt csv html json sql + - txt csv/tsv html json sql -------------------------------------------------------------------------------------- aregister Y Y Y Y balance Y 1 Y 1 Y 1,2 Y @@ -1132,7 +1186,7 @@ Journal A decimal mark can be written as a period or a comma: 1.23 - 1,23456780000009 + 1,23 In the integer part of the quantity (left of the decimal mark), groups of digits can optionally be separated by a digit group mark - a space, @@ -1143,21 +1197,15 @@ Journal INR 9,99,99,999.00 1 000 000.9455 - Note, a number containing a single digit group mark and no decimal mark - is ambiguous. Are these digit group marks or decimal marks ? + hledger is not biased towards period or comma decimal marks, so a num- + ber containing just one period or comma, like 1,000 or 1.000, is am- + biguous. In such cases hledger assumes it is a decimal mark, parsing + both of these as 1. - 1,000 - 1.000 - - If you don't tell it otherwise, hledger will assume both of the above - are decimal marks, parsing both numbers as 1. - - To prevent confusing parsing mistakes and undetected typos, especially - if your data contains digit group marks (eg, thousands separators), we - recommend explicitly declaring the decimal mark character in each jour- - nal file, using a directive at the top of the file. The decimal-mark - directive is best, otherwise commodity directives will also work. - These are described below. + To disambiguate these and ensure accurate number parsing, especially if + you use digit group marks, we recommend declaring the decimal mark. + You can declare it for each file with decimal-mark directives, or for + each commodity with commodity directives (described below). Commodity Amounts in hledger have both a "quantity", which is a signed decimal @@ -1196,66 +1244,45 @@ Journal Commodity display style For the amounts in each commodity, hledger chooses a consistent display - style to use in most reports. (Exceptions: price amounts, and all - amounts displayed by the print command, are displayed with all of their - decimal digits visible.) + style (symbol placement, decimal mark and digit group marks, number of + decimal digits) to use in most reports. This is inferred as follows: - A commodity's display style is inferred as follows. + First, if there's a D directive declaring a default commodity, that + commodity symbol and amount format is applied to all no-symbol amounts + in the journal. - First, if a default commodity is declared with D, this commodity and - its style is applied to any no-symbol amounts in the journal. + Then each commodity's display style is determined from its commodity + directive. We recommend always declaring commodities with commodity + directives, since they help ensure consistent display styles and preci- + sions, and bring other benefits such as error checking for commodity + symbols. - Then each commodity's style is inferred from one of the following, in - order of preference: + But if a commodity directive is not present, hledger infers a commod- + ity's display styles from its amounts as they are written in the jour- + nal (excluding cost amounts and amounts in periodic transaction rules + or auto posting rules). It uses - o The commodity directive for that commodity (including the no-symbol - commodity), if any. + o the symbol placement and decimal mark of the first amount seen - o The amounts in that commodity seen in the journal's transactions. - (Posting amounts only; prices and periodic or auto rules are ignored, - currently.) + o the digit group marks of the first amount with digit group marks - o The built-in fallback style, which looks like this: $1000.00. (Sym- - bol on the left, period decimal mark, two decimal places.) + o and the maximum number of decimal digits seen across all amounts. - A style is inferred from journal amounts as follows: + And as fallback if no applicable amounts are found, it would use a de- + fault style, like $1000.00 (symbol on the left with no space, period as + decimal mark, and two decimal digits). - o Use the general style (decimal mark, symbol placement) of the first - amount - - o Use the first-seen digit group style (digit group mark, digit group - sizes), if any - - o Use the maximum number of decimal places of all. - - Cost amounts don't affect the commodity display style directly, but oc- - casionally they can do so indirectly (eg when a posting's amount is in- - ferred using a cost). If you find this causing problems, use a commod- - ity directive to fix the display style. - - To summarise: each commodity's amounts will be normalised to (a) the - style declared by a commodity directive, or (b) the style of the first - posting amount in the journal, with the first-seen digit group style - and the maximum-seen number of decimal places. So if your reports are - showing amounts in a way you don't like, eg with too many decimal - places, use a commodity directive. Some examples: - - # declare euro, dollar, bitcoin and no-symbol commodities and set their - # input number formats and output display styles: - commodity EUR 1.000, - commodity $1000.00 - commodity 1000.00000000 BTC - commodity 1 000. - - The inferred commodity style can be overridden by supplying a command - line option. + Finally, commodity styles can be overridden by the -c/--commodity-style + command line option. Rounding Amounts are stored internally as decimal numbers with up to 255 decimal - places, and displayed with the number of decimal places specified by - the commodity display style. Note, hledger uses banker's rounding: it - rounds to the nearest even number, eg 0.5 displayed with zero decimal - places is "0"). + places. They are displayed with their original journal precisions by + print and print-like reports, and rounded to their display precision + (the number of decimal digits specified by the commodity display style) + by other reports. When rounding, hledger uses banker's rounding (it + rounds to the nearest even digit). So eg 0.5 displayed with zero deci- + mal digits appears as "0". Costs After a posting amount, you can note its cost (when buying) or selling @@ -2084,84 +2111,76 @@ Journal $ hledger accounts --alias assets=bassetts type:a commodity directive - You can use commodity directives to declare your commodities. In fact - the commodity directive performs several functions at once: + The commodity directive performs several functions: - 1. It declares commodities which may be used in the journal. This can - optionally be enforced, providing useful error checking. (Cf Com- - modity error checking) + 1. It declares which commodity symbols may be used in the journal, en- + abling useful error checking with strict mode or the check command. + (See Commodity error checking below.) - 2. It declares which decimal mark character (period or comma), to ex- - pect when parsing input - useful to disambiguate international num- - ber formats in your data. Without this, hledger will parse both - 1,000 and 1.000 as 1. (Cf Amounts) + 2. It declares the precision with which this commodity's amounts should + be compared when checking for balanced transactions. - 3. It declares how to render the commodity's amounts when displaying - output - the decimal mark, any digit group marks, the number of dec- - imal places, symbol placement and so on. (Cf Commodity display - style) + 3. It declares how this commodity's amounts should be displayed, eg + their symbol placement, digit group mark if any, digit group sizes, + decimal mark (period or comma), and the number of decimal places. + (See Commodity display style above.) - You will run into one of the problems solved by commodity directives - sooner or later, so we recommend using them, for robust and predictable - parsing and display. + 4. It sets which decimal mark (period or comma) to expect when parsing + subsequent amounts in this commodity (if there is no decimal-mark + directive in effect. See Decimal marks, digit group marks above. + For related dev discussion, see #793.) - Generally you should put them at the top of your journal file (since - for function 2, they affect only following amounts, cf #793). + Declaring commodities solves several common parsing/display problems, + so we recommend it. Generally you should put commodity directives at + the top of your journal file (because function 4 is position-sensi- + tive). - A commodity directive is just the word commodity followed by a sample - amount, like this: - - ;commodity SAMPLEAMOUNT + Commodity directive syntax + A commodity directive is normally the word commodity followed by a sam- + ple amount (and optionally a comment). Only the amount's symbol and + format is significant. Eg: commodity $1000.00 - commodity 1,000.0000 AAAA ; optional same-line comment + commodity 1.000,00 EUR + commodity 1 000 000.0000 ; the no-symbol commodity - It may also be written on multiple lines, and use the format subdirec- - tive, as in Ledger. Note in this case the commodity symbol appears - twice; it must be the same in both places: + A commodity directive's sample amount must always include a period or + comma decimal mark (this rule helps disambiguate decimal marks and + digit group marks). If you don't want to show any decimal digits, + write the decimal mark at the end: - ;commodity SYMBOL - ; format SAMPLEAMOUNT + commodity 1000. AAAA ; show AAAA with no decimals + + Commodity symbols containing spaces, numbers, or punctuation must be + enclosed in double quotes, as usual: + + commodity 1.0000 "AAAA 2023" + + Commodity directives normally include a sample amount, but can declare + only a symbol (ie, just function 1 above): + + commodity $ + commodity INR + commodity "AAAA 2023" + commodity "" ; the no-symbol commodity + + Commodity directives may also be written with an indented format subdi- + rective, as in Ledger. The symbol is repeated and must be the same in + both places. Other subdirectives are currently ignored: ; display indian rupees with currency name on the left, ; thousands, lakhs and crores comma-separated, ; period as decimal point, and two decimal places. commodity INR format INR 1,00,00,000.00 - - Other indented subdirectives are currently ignored. - - Remember that if the commodity symbol contains spaces, numbers, or - punctuation, it must be enclosed in double quotes (cf Commodity). - - The amount's quantity does not matter; only the format is significant. - It must include a decimal mark - either a period or a comma - followed - by 0 or more decimal digits. - - A few more examples: - - # number formats for $, EUR, INR and the no-symbol commodity: - commodity $1,000.00 - commodity EUR 1.000,00 - commodity INR 9,99,99,999.0 - commodity 1 000 000. - - Note hledger normally uses banker's rounding, so 0.5 displayed with - zero decimal digits is "0". (More at Commodity display style.) - - Even in the presence of commodity directives, the commodity display - style can still be overridden by supplying a command line option. + an unsupported subdirective ; ignored by hledger Commodity error checking - In strict mode, enabled with the -s/--strict flag, hledger will report - an error if a commodity symbol is used that has not been declared by a - commodity directive. This works similarly to account error checking, - see the notes there for more details. - - Note, this disallows amounts without a commodity symbol, because cur- - rently it's not possible (?) to declare the "no-symbol" commodity with - a directive. This is one exception for convenience: zero amounts are - always allowed to have no commodity symbol. + In strict mode (-s/--strict) (or when you run hledger check commodi- + ties), hledger will report an error if an undeclared commodity symbol + is used. (With one exception: zero amounts are always allowed to have + no commodity symbol.) It works like account error checking (described + above). decimal-mark directive You can use a decimal-mark directive - usually one per file, at the top @@ -2174,20 +2193,20 @@ Journal decimal-mark , - This prevents any ambiguity when parsing numbers in the file, so we - recommend it, especially if the file contains digit group marks (eg + This prevents any ambiguity when parsing numbers in the file, so we + recommend it, especially if the file contains digit group marks (eg thousands separators). include directive - You can pull in the content of additional files by writing an include + You can pull in the content of additional files by writing an include directive, like this: include FILEPATH - Only journal files can include, and only journal, timeclock or timedot + Only journal files can include, and only journal, timeclock or timedot files can be included (not CSV files, currently). - If the file path does not begin with a slash, it is relative to the + If the file path does not begin with a slash, it is relative to the current file's folder. A tilde means home directory, eg: include ~/main.journal. @@ -2196,27 +2215,27 @@ Journal *.journal. There is limited support for recursive wildcards: **/ (the slash is re- - quired) matches 0 or more subdirectories. It's not super convenient - since you have to avoid include cycles and including directories, but + quired) matches 0 or more subdirectories. It's not super convenient + since you have to avoid include cycles and including directories, but this can be done, eg: include */**/*.journal. The path may also be prefixed to force a specific file format, overrid- - ing the file extension (as described in Data formats): include time- + ing the file extension (as described in Data formats): include time- dot:~/notes/2023*.md. P directive The P directive declares a market price, which is a conversion rate be- - tween two commodities on a certain date. This allows value reports to + tween two commodities on a certain date. This allows value reports to convert amounts of one commodity to their value in another, on or after - that date. These prices are often obtained from a stock exchange, + that date. These prices are often obtained from a stock exchange, cryptocurrency exchange, the or foreign exchange market. The format is: P DATE COMMODITY1SYMBOL COMMODITY2AMOUNT - DATE is a simple date, COMMODITY1SYMBOL is the symbol of the commodity - being priced, and COMMODITY2AMOUNT is the amount (symbol and quantity) + DATE is a simple date, COMMODITY1SYMBOL is the symbol of the commodity + being priced, and COMMODITY2AMOUNT is the amount (symbol and quantity) of commodity 2 that one unit of commodity 1 is worth on this date. Ex- amples: @@ -2226,15 +2245,15 @@ Journal # and $1.40 from 2010-01-01 onward: P 2010-01-01 $1.40 - The -V, -X and --value flags use these market prices to show amount + The -V, -X and --value flags use these market prices to show amount values in another commodity. See Value reporting. payee directive payee PAYEE NAME This directive can be used to declare a limited set of payees which may - appear in transaction descriptions. The "payees" check will report an - error if any transaction refers to a payee that has not been declared. + appear in transaction descriptions. The "payees" check will report an + error if any transaction refers to a payee that has not been declared. Eg: payee Whole Foods @@ -2244,52 +2263,52 @@ Journal tag directive tag TAGNAME - This directive can be used to declare a limited set of tag names al- + This directive can be used to declare a limited set of tag names al- lowed in tags. TAGNAME should be a valid tag name (no spaces). Eg: tag item-id Any indented subdirectives are currently ignored. - The "tags" check will report an error if any undeclared tag name is + The "tags" check will report an error if any undeclared tag name is used. It is quite easy to accidentally create a tag through normal use - of colons in comments(#comments]; if you want to prevent this, you can + of colons in comments(#comments]; if you want to prevent this, you can declare and check your tags . Periodic transactions The ~ directive declares recurring transactions. Such directives allow - hledger to generate temporary future transactions (visible in reports, + hledger to generate temporary future transactions (visible in reports, not in the journal file) to help with forecasting or budgeting. - Periodic transactions can be a little tricky, so before you use them, + Periodic transactions can be a little tricky, so before you use them, read this whole section, or at least these tips: - 1. Two spaces accidentally added or omitted will cause you trouble - + 1. Two spaces accidentally added or omitted will cause you trouble - read about this below. - 2. For troubleshooting, show the generated transactions with hledger - print --forecast tag:generated or hledger register --forecast + 2. For troubleshooting, show the generated transactions with hledger + print --forecast tag:generated or hledger register --forecast tag:generated. - 3. Forecasted transactions will begin only after the last non-fore- + 3. Forecasted transactions will begin only after the last non-fore- casted transaction's date. - 4. Forecasted transactions will end 6 months from today, by default. + 4. Forecasted transactions will end 6 months from today, by default. See below for the exact start/end rules. - 5. period expressions can be tricky. Their documentation needs im- + 5. period expressions can be tricky. Their documentation needs im- provement, but is worth studying. - 6. Some period expressions with a repeating interval must begin on a - natural boundary of that interval. Eg in weekly from DATE, DATE - must be a monday. ~ weekly from 2019/10/1 (a tuesday) will give an + 6. Some period expressions with a repeating interval must begin on a + natural boundary of that interval. Eg in weekly from DATE, DATE + must be a monday. ~ weekly from 2019/10/1 (a tuesday) will give an error. 7. Other period expressions with an interval are automatically expanded - to cover a whole number of that interval. (This is done to improve + to cover a whole number of that interval. (This is done to improve reports, but it also affects periodic transactions. Yes, it's a bit - inconsistent with the above.) Eg: ~ every 10th day of month from - 2023/01, which is equivalent to ~ every 10th day of month from + inconsistent with the above.) Eg: ~ every 10th day of month from + 2023/01, which is equivalent to ~ every 10th day of month from 2023/01/01, will be adjusted to start on 2019/12/10. Periodic rule syntax @@ -2307,14 +2326,14 @@ Journal expenses:utilities $400 assets:bank:checking - The period expression is the same syntax used for specifying multi-pe- - riod reports, just interpreted differently; there, it specifies report + The period expression is the same syntax used for specifying multi-pe- + riod reports, just interpreted differently; there, it specifies report periods; here it specifies recurrence dates (the periods' start dates). Periodic rules and relative dates - Partial or relative dates (like 12/31, 25, tomorrow, last week, next - quarter) are usually not recommended in periodic rules, since the re- - sults will change as time passes. If used, they will be interpreted + Partial or relative dates (like 12/31, 25, tomorrow, last week, next + quarter) are usually not recommended in periodic rules, since the re- + sults will change as time passes. If used, they will be interpreted relative to, in order of preference: 1. the first day of the default year specified by a recent Y directive @@ -2323,11 +2342,11 @@ Journal 3. or the date on which you are running the report. - They will not be affected at all by report period or forecast period + They will not be affected at all by report period or forecast period dates. Two spaces between period expression and description! - If the period expression is followed by a transaction description, + If the period expression is followed by a transaction description, these must be separated by two or more spaces. This helps hledger know where the period expression ends, so that descriptions can not acciden- tally alter their meaning, as in this example: @@ -2341,21 +2360,21 @@ Journal So, - o Do write two spaces between your period expression and your transac- + o Do write two spaces between your period expression and your transac- tion description, if any. - o Don't accidentally write two spaces in the middle of your period ex- + o Don't accidentally write two spaces in the middle of your period ex- pression. Auto postings The = directive declares a rule for generating temporary extra postings on transactions. Wherever the rule matches an existing posting, it can - add one or more companion postings below that one, optionally influ- + add one or more companion postings below that one, optionally influ- enced by the matched posting's amount. This can be useful for generat- ing tax postings with a standard percentage, for example. - Note that depending on generated data is not ideal for financial - records (it's less portable, less future-proof, less auditable by oth- + Note that depending on generated data is not ideal for financial + records (it's less portable, less future-proof, less auditable by oth- ers, and less robust, since other features like balance assertions will depend on using or not using --auto). @@ -2366,27 +2385,27 @@ Journal ... ACCOUNT [AMOUNT] - except the first line is an equals sign (mnemonic: = suggests match- - ing), followed by a query (which matches existing postings), and each - "posting" line describes a posting to be generated, and the posting + except the first line is an equals sign (mnemonic: = suggests match- + ing), followed by a query (which matches existing postings), and each + "posting" line describes a posting to be generated, and the posting amounts can be: - o a normal amount with a commodity symbol, eg $2. This will be used + o a normal amount with a commodity symbol, eg $2. This will be used as-is. o a number, eg 2. The commodity symbol (if any) from the matched post- ing will be added to this. - o a numeric multiplier, eg *2 (a star followed by a number N). The + o a numeric multiplier, eg *2 (a star followed by a number N). The matched posting's amount (and total price, if any) will be multiplied by N. - o a multiplier with a commodity symbol, eg *$2 (a star, number N, and + o a multiplier with a commodity symbol, eg *$2 (a star, number N, and symbol S). The matched posting's amount will be multiplied by N, and its commodity symbol will be replaced with S. - Any query term containing spaces must be enclosed in single or double - quotes, as on the command line. Eg, note the quotes around the second + Any query term containing spaces must be enclosed in single or double + quotes, as on the command line. Eg, note the quotes around the second query term below: = expenses:groceries 'expenses:dining out' @@ -2425,29 +2444,29 @@ Journal Auto postings and multiple files An auto posting rule can affect any transaction in the current file, or - in any parent file or child file. Note, currently it will not affect + in any parent file or child file. Note, currently it will not affect sibling files (when multiple -f/--file are used - see #1212). Auto postings and dates - A posting date (or secondary date) in the matched posting, or (taking - precedence) a posting date in the auto posting rule itself, will also + A posting date (or secondary date) in the matched posting, or (taking + precedence) a posting date in the auto posting rule itself, will also be used in the generated posting. Auto postings and transaction balancing / inferred amounts / balance asser- tions Currently, auto postings are added: - o after missing amounts are inferred, and transactions are checked for + o after missing amounts are inferred, and transactions are checked for balancedness, o but before balance assertions are checked. - Note this means that journal entries must be balanced both before and + Note this means that journal entries must be balanced both before and after auto postings are added. This changed in hledger 1.12+; see #893 for background. - This also means that you cannot have more than one auto-posting with a - missing amount applied to a given transaction, as it will be unable to + This also means that you cannot have more than one auto-posting with a + missing amount applied to a given transaction, as it will be unable to infer amounts. Auto posting tags @@ -2456,11 +2475,11 @@ Journal o generated-posting:= QUERY - shows this was generated by an auto post- ing rule, and the query - o _generated-posting:= QUERY - a hidden tag, which does not appear in + o _generated-posting:= QUERY - a hidden tag, which does not appear in hledger's output. This can be used to match postings generated "just now", rather than generated in the past and saved to the journal. - Also, any transaction that has been changed by auto posting rules will + Also, any transaction that has been changed by auto posting rules will have these tags added: o modified: - this transaction was modified @@ -2469,24 +2488,24 @@ Journal tion was modified "just now". Auto postings on forecast transactions only - Tip: you can can make auto postings that will apply to forecast trans- - actions but not recorded transactions, by adding tag:_generated-trans- - action to their QUERY. This can be useful when generating new journal + Tip: you can can make auto postings that will apply to forecast trans- + actions but not recorded transactions, by adding tag:_generated-trans- + action to their QUERY. This can be useful when generating new journal entries to be saved in the journal. Other syntax - hledger journal format supports quite a few other features, mainly to - make interoperating with or converting from Ledger easier. Note some - of the features below are powerful and can be useful in special cases, - but in general, features in this section are considered less important - or even not recommended for most users. Downsides are mentioned to + hledger journal format supports quite a few other features, mainly to + make interoperating with or converting from Ledger easier. Note some + of the features below are powerful and can be useful in special cases, + but in general, features in this section are considered less important + or even not recommended for most users. Downsides are mentioned to help you decide if you want to use them. Balance assignments - Ledger-style balance assignments are also supported. These are like - balance assertions, but with no posting amount on the left side of the - equals sign; instead it is calculated automatically so as to satisfy - the assertion. This can be a convenience during data entry, eg when + Ledger-style balance assignments are also supported. These are like + balance assertions, but with no posting amount on the left side of the + equals sign; instead it is calculated automatically so as to satisfy + the assertion. This can be a convenience during data entry, eg when setting opening balances: ; starting a new journal, set asset account balances @@ -2504,15 +2523,15 @@ Journal expenses:misc The calculated amount depends on the account's balance in the commodity - at that point (which depends on the previously-dated postings of the - commodity to that account since the last balance assertion or assign- + at that point (which depends on the previously-dated postings of the + commodity to that account since the last balance assertion or assign- ment). - Downsides: using balance assignments makes your journal less explicit; + Downsides: using balance assignments makes your journal less explicit; to know the exact amount posted, you have to run hledger or do the cal- - culations yourself, instead of just reading it. Also balance assign- + culations yourself, instead of just reading it. Also balance assign- ments' forcing of balances can hide errors. These things make your fi- - nancial data less portable, less future-proof, and less trustworthy in + nancial data less portable, less future-proof, and less trustworthy in an audit. Balance assignments and prices @@ -2527,31 +2546,31 @@ Journal (a) $1 @ 2 = $1 @ 2 Balance assignments and multiple files - Balance assignments handle multiple files like balance assertions. - They see balance from other files previously included from the current + Balance assignments handle multiple files like balance assertions. + They see balance from other files previously included from the current file, but not from previous sibling or parent files. Bracketed posting dates - For setting posting dates and secondary posting dates, Ledger's brack- + For setting posting dates and secondary posting dates, Ledger's brack- eted date syntax is also supported: [DATE], [DATE=DATE2] or [=DATE2] in - posting comments. hledger will attempt to parse any square-bracketed - sequence of the 0123456789/-.= characters in this way. With this syn- - tax, DATE infers its year from the transaction and DATE2 infers its + posting comments. hledger will attempt to parse any square-bracketed + sequence of the 0123456789/-.= characters in this way. With this syn- + tax, DATE infers its year from the transaction and DATE2 infers its year from DATE. - Downsides: another syntax to learn, redundant with hledger's + Downsides: another syntax to learn, redundant with hledger's date:/date2: tags, and confusingly similar to Ledger's lot date syntax. D directive D AMOUNT - This directive sets a default commodity, to be used for any subsequent - commodityless amounts (ie, plain numbers) seen while parsing the jour- - nal. This effect lasts until the next D directive, or the end of the + This directive sets a default commodity, to be used for any subsequent + commodityless amounts (ie, plain numbers) seen while parsing the jour- + nal. This effect lasts until the next D directive, or the end of the journal. - For compatibility/historical reasons, D also acts like a commodity di- - rective (setting the commodity's decimal mark for parsing and display + For compatibility/historical reasons, D also acts like a commodity di- + rective (setting the commodity's decimal mark for parsing and display style for output). So its argument is not just a commodity symbol, but a full amount demonstrating the style. The amount must include a deci- mal mark (either period or comma). Eg: @@ -2566,23 +2585,23 @@ Journal Interactions with other directives: - For setting a commodity's display style, a commodity directive has + For setting a commodity's display style, a commodity directive has highest priority, then a D directive. - For detecting a commodity's decimal mark during parsing, decimal-mark + For detecting a commodity's decimal mark during parsing, decimal-mark has highest priority, then commodity, then D. - For checking commodity symbols with the check command, a commodity di- + For checking commodity symbols with the check command, a commodity di- rective is required (hledger check commodities ignores D directives). - Downsides: omitting commodity symbols makes your financial data less - explicit, less portable, and less trustworthy in an audit. It is usu- - ally an unsustainable shortcut; sooner or later you will want to track - multiple commodities. D is overloaded with functions redundant with + Downsides: omitting commodity symbols makes your financial data less + explicit, less portable, and less trustworthy in an audit. It is usu- + ally an unsustainable shortcut; sooner or later you will want to track + multiple commodities. D is overloaded with functions redundant with commodity and decimal-mark. And it works differently from Ledger's D. apply account directive - This directive sets a default parent account, which will be prepended + This directive sets a default parent account, which will be prepended to all accounts in following entries, until an end apply account direc- tive or end of current file. Eg: @@ -2604,10 +2623,10 @@ Journal Account names entered via hledger add or hledger-web are not affected. - Account aliases, if any, are applied after the parent account is + Account aliases, if any, are applied after the parent account is prepended. - Downsides: this can make your financial data less explicit, less + Downsides: this can make your financial data less explicit, less portable, and less trustworthy in an audit. Y directive @@ -2617,7 +2636,7 @@ Journal year YEAR apply year YEAR - The space is optional. This sets a default year to be used for subse- + The space is optional. This sets a default year to be used for subse- quent dates which don't specify a year. Eg: Y2009 ; set default year to 2009 @@ -2638,57 +2657,57 @@ Journal Downsides: omitting the year (from primary transaction dates, at least) makes your financial data less explicit, less portable, and less trust- - worthy in an audit. Such dates can get separated from their corre- - sponding Y directive, eg when evaluating a region of the journal in - your editor. A missing Y directive makes reports dependent on today's + worthy in an audit. Such dates can get separated from their corre- + sponding Y directive, eg when evaluating a region of the journal in + your editor. A missing Y directive makes reports dependent on today's date. Secondary dates A secondary date is written after the primary date, following an equals - sign. If the year is omitted, the primary date's year is assumed. - When running reports, the primary (left) date is used by default, but - with the --date2 flag (or --aux-date or --effective), the secondary + sign. If the year is omitted, the primary date's year is assumed. + When running reports, the primary (left) date is used by default, but + with the --date2 flag (or --aux-date or --effective), the secondary (right) date will be used instead. - The meaning of secondary dates is up to you, but it's best to follow a - consistent rule. Eg "primary = the bank's clearing date, secondary = + The meaning of secondary dates is up to you, but it's best to follow a + consistent rule. Eg "primary = the bank's clearing date, secondary = date the transaction was initiated, if different". - Downsides: makes your financial data more complicated, less portable, + Downsides: makes your financial data more complicated, less portable, and less trustworthy in an audit. Keeping the meaning of the two dates - consistent requires discipline, and you have to remember which report- - ing mode is appropriate for a given report. Posting dates are simpler + consistent requires discipline, and you have to remember which report- + ing mode is appropriate for a given report. Posting dates are simpler and better. Star comments - Lines beginning with * (star/asterisk) are also comment lines. This + Lines beginning with * (star/asterisk) are also comment lines. This feature allows Emacs users to insert org headings in their journal, al- lowing them to fold/unfold/navigate it like an outline when viewed with org mode. - Downsides: another, unconventional comment syntax to learn. Decreases - your journal's portability. And switching to Emacs org mode just for - folding/unfolding meant losing the benefits of ledger mode; nowadays - you can add outshine mode to ledger mode to get folding without losing + Downsides: another, unconventional comment syntax to learn. Decreases + your journal's portability. And switching to Emacs org mode just for + folding/unfolding meant losing the benefits of ledger mode; nowadays + you can add outshine mode to ledger mode to get folding without losing ledger mode's features. Valuation expressions - Ledger allows a valuation function or value to be written in double + Ledger allows a valuation function or value to be written in double parentheses after an amount. hledger ignores these. Virtual postings - A posting with parentheses around the account name ((some:account)) is - called a unbalanced virtual posting. Such postings do not participate - in transaction balancing. (And if you write them without an amount, a - zero amount is always inferred.) These can occasionally be convenient - for special circumstances, but they violate double entry bookkeeping - and make your data less portable across applications, so many people + A posting with parentheses around the account name ((some:account)) is + called a unbalanced virtual posting. Such postings do not participate + in transaction balancing. (And if you write them without an amount, a + zero amount is always inferred.) These can occasionally be convenient + for special circumstances, but they violate double entry bookkeeping + and make your data less portable across applications, so many people avoid using them at all. - A posting with brackets around the account name ([some:account]) is - called a balanced virtual posting. The balanced virtual postings in a + A posting with brackets around the account name ([some:account]) is + called a balanced virtual posting. The balanced virtual postings in a transaction must add up to zero, just like ordinary postings, but sepa- - rately from them. These are not part of double entry bookkeeping ei- + rately from them. These are not part of double entry bookkeeping ei- ther, but they are at least balanced. An example: 2022-01-01 buy food with cash, update budget envelope subaccounts, & something else @@ -2699,13 +2718,13 @@ Journal [assets:checking:available] $10 ; <- (something:else) $5 ; <- this is not required to balance - Ordinary postings, whose account names are neither parenthesised nor - bracketed, are called real postings. You can exclude virtual postings + Ordinary postings, whose account names are neither parenthesised nor + bracketed, are called real postings. You can exclude virtual postings from reports with the -R/--real flag or a real:1 query. Other Ledger directives These other Ledger directives are currently accepted but ignored. This - allows hledger to read more Ledger files, but be aware that hledger's + allows hledger to read more Ledger files, but be aware that hledger's reports may differ from Ledger's if you use these. apply fixed COMM AMT @@ -2726,35 +2745,35 @@ Journal value EXPR --command-line-flags - See also https://hledger.org/ledger.html for a detailed hledger/Ledger + See also https://hledger.org/ledger.html for a detailed hledger/Ledger syntax comparison. CSV - hledger can read CSV files (Character Separated Value - usually comma, - semicolon, or tab) containing dated records, automatically converting + hledger can read CSV files (Character Separated Value - usually comma, + semicolon, or tab) containing dated records, automatically converting each record into a transaction. (To learn about writing CSV, see CSV output.) - For best error messages when reading CSV/TSV/SSV files, make sure they + For best error messages when reading CSV/TSV/SSV files, make sure they have a corresponding .csv, .tsv or .ssv file extension or use a hledger file prefix (see File Extension below). Each CSV file must be described by a corresponding rules file. - This contains rules describing the CSV data (header line, fields lay- - out, date format etc.), how to construct hledger transactions from it, - and how to categorise transactions based on description or other at- + This contains rules describing the CSV data (header line, fields lay- + out, date format etc.), how to construct hledger transactions from it, + and how to categorise transactions based on description or other at- tributes. - By default hledger looks for a rules file named like the CSV file with - an extra .rules extension, in the same directory. Eg when asked to + By default hledger looks for a rules file named like the CSV file with + an extra .rules extension, in the same directory. Eg when asked to read foo/FILE.csv, hledger looks for foo/FILE.csv.rules. You can spec- - ify a different rules file with the --rules-file option. If no rules - file is found, hledger will create a sample rules file, which you'll + ify a different rules file with the --rules-file option. If no rules + file is found, hledger will create a sample rules file, which you'll need to adjust. - At minimum, the rules file must identify the date and amount fields, - and often it also specifies the date format and how many header lines + At minimum, the rules file must identify the date and amount fields, + and often it also specifies the date format and how many header lines there are. Here's a simple CSV file and a rules file for it: Date, Description, Id, Amount @@ -2771,56 +2790,56 @@ CSV income:unknown -10.23 There's an introductory Importing CSV data tutorial on hledger.org, and - more CSV rules examples below, and a larger collection at + more CSV rules examples below, and a larger collection at https://github.com/simonmichael/hledger/tree/master/examples/csv. CSV rules cheatsheet The following kinds of rule can appear in the rules file, in any order. (Blank lines and lines beginning with # or ; or * are ignored.) - source optionally declare which file to read data + source optionally declare which file to read data from - separator declare the field separator, instead of rely- + separator declare the field separator, instead of rely- ing on file extension skip skip one or more header lines at start of file date-format declare how to parse CSV dates/date-times - timezone declare the time zone of ambiguous CSV date- + timezone declare the time zone of ambiguous CSV date- times - newest-first improve txn order when: there are multiple + newest-first improve txn order when: there are multiple records, newest first, all with the same date - intra-day-reversed improve txn order when: same-day txns are in + intra-day-reversed improve txn order when: same-day txns are in opposite order to the overall file - decimal-mark declare the decimal mark used in CSV amounts, + decimal-mark declare the decimal mark used in CSV amounts, when ambiguous - fields list name CSV fields for easy reference, and op- + fields list name CSV fields for easy reference, and op- tionally assign their values to hledger fields - Field assignment assign a CSV value or interpolated text value + Field assignment assign a CSV value or interpolated text value to a hledger field if block conditionally assign values to hledger fields, or skip a record or end (skip rest of file) if table conditionally assign values to hledger fields, using compact syntax - balance-type select which type of balance assertions/as- + balance-type select which type of balance assertions/as- signments to generate include inline another CSV rules file - Working with CSV tips can be found below, including How CSV rules are + Working with CSV tips can be found below, including How CSV rules are evaluated. source - If you tell hledger to read a csv file with -f foo.csv, it will look - for rules in foo.csv.rules. Or, you can tell it to read the rules - file, with -f foo.csv.rules, and it will look for data in foo.csv + If you tell hledger to read a csv file with -f foo.csv, it will look + for rules in foo.csv.rules. Or, you can tell it to read the rules + file, with -f foo.csv.rules, and it will look for data in foo.csv (since 1.30). - These are mostly equivalent, but the second method provides some extra - features. For one, the data file can be missing, without causing an - error; it is just considered empty. And, you can specify a different + These are mostly equivalent, but the second method provides some extra + features. For one, the data file can be missing, without causing an + error; it is just considered empty. And, you can specify a different data file by adding a "source" rule: source ./Checking1.csv - If you specify just a file name with no path, hledger will look for it + If you specify just a file name with no path, hledger will look for it in your system's downloads directory (~/Downloads, currently): source Checking1.csv @@ -2833,9 +2852,9 @@ CSV See also "Working with CSV > Reading files specified by rule". separator - You can use the separator rule to read other kinds of character-sepa- - rated data. The argument is any single separator character, or the - words tab or space (case insensitive). Eg, for comma-separated values + You can use the separator rule to read other kinds of character-sepa- + rated data. The argument is any single separator character, or the + words tab or space (case insensitive). Eg, for comma-separated values (CSV): separator , @@ -2848,32 +2867,32 @@ CSV separator TAB - If the input file has a .csv, .ssv or .tsv file extension (or a csv:, + If the input file has a .csv, .ssv or .tsv file extension (or a csv:, ssv:, tsv: prefix), the appropriate separator will be inferred automat- ically, and you won't need this rule. skip skip N - The word skip followed by a number (or no number, meaning 1) tells - hledger to ignore this many non-empty lines at the start of the input - data. You'll need this whenever your CSV data contains header lines. - Note, empty and blank lines are skipped automatically, so you don't + The word skip followed by a number (or no number, meaning 1) tells + hledger to ignore this many non-empty lines at the start of the input + data. You'll need this whenever your CSV data contains header lines. + Note, empty and blank lines are skipped automatically, so you don't need to count those. - skip has a second meaning: it can be used inside if blocks (described - below), to skip one or more records whenever the condition is true. + skip has a second meaning: it can be used inside if blocks (described + below), to skip one or more records whenever the condition is true. Records skipped in this way are ignored, except they are still required to be valid CSV. date-format date-format DATEFMT - This is a helper for the date (and date2) fields. If your CSV dates - are not formatted like YYYY-MM-DD, YYYY/MM/DD or YYYY.MM.DD, you'll - need to add a date-format rule describing them with a strptime-style - date parsing pattern - see https://hackage.haskell.org/pack- - age/time/docs/Data-Time-Format.html#v:formatTime. The pattern must + This is a helper for the date (and date2) fields. If your CSV dates + are not formatted like YYYY-MM-DD, YYYY/MM/DD or YYYY.MM.DD, you'll + need to add a date-format rule describing them with a strptime-style + date parsing pattern - see https://hackage.haskell.org/pack- + age/time/docs/Data-Time-Format.html#v:formatTime. The pattern must parse the CSV date value completely. Some examples: # MM/DD/YY @@ -2893,33 +2912,33 @@ CSV timezone timezone TIMEZONE - When CSV contains date-times that are implicitly in some time zone + When CSV contains date-times that are implicitly in some time zone other than yours, but containing no explicit time zone information, you - can use this rule to declare the CSV's native time zone, which helps + can use this rule to declare the CSV's native time zone, which helps prevent off-by-one dates. - When the CSV date-times do contain time zone information, you don't - need this rule; instead, use %Z in date-format (or %z, %EZ, %Ez; see + When the CSV date-times do contain time zone information, you don't + need this rule; instead, use %Z in date-format (or %z, %EZ, %Ez; see the formatTime link above). In either of these cases, hledger will do a time-zone-aware conversion, localising the CSV date-times to your current system time zone. If you prefer to localise to some other time zone, eg for reproducibility, you - can (on unix at least) set the output timezone with the TZ environment + can (on unix at least) set the output timezone with the TZ environment variable, eg: $ TZ=-1000 hledger print -f foo.csv # or TZ=-1000 hledger import foo.csv - timezone currently does not understand timezone names, except "UTC", - "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", or "PDT". For + timezone currently does not understand timezone names, except "UTC", + "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", or "PDT". For others, use numeric format: +HHMM or -HHMM. newest-first hledger tries to ensure that the generated transactions will be ordered chronologically, including same-day transactions. Usually it can auto- detect how the CSV records are ordered. But if it encounters CSV where - all records are on the same date, it assumes that the records are old- - est first. If in fact the CSV's records are normally newest first, + all records are on the same date, it assumes that the records are old- + est first. If in fact the CSV's records are normally newest first, like: 2022-10-01, txn 3... @@ -2933,9 +2952,9 @@ CSV newest-first intra-day-reversed - If CSV records within a single day are ordered opposite to the overall - record order, you can add the intra-day-reversed rule to improve the - order of journal entries. Eg, here the overall record order is newest + If CSV records within a single day are ordered opposite to the overall + record order, you can add the intra-day-reversed rule to improve the + order of journal entries. Eg, here the overall record order is newest first, but same-day records are oldest first: 2022-10-02, txn 3... @@ -2953,10 +2972,10 @@ CSV decimal-mark , - hledger automatically accepts either period or comma as a decimal mark - when parsing numbers (cf Amounts). However if any numbers in the CSV - contain digit group marks, such as thousand-separating commas, you - should declare the decimal mark explicitly with this rule, to avoid + hledger automatically accepts either period or comma as a decimal mark + when parsing numbers (cf Amounts). However if any numbers in the CSV + contain digit group marks, such as thousand-separating commas, you + should declare the decimal mark explicitly with this rule, to avoid misparsed numbers. fields list @@ -2965,17 +2984,17 @@ CSV A fields list (the word fields followed by comma-separated field names) is optional, but convenient. It does two things: - 1. It names the CSV field in each column. This can be convenient if - you are referencing them in other rules, so you can say %SomeField + 1. It names the CSV field in each column. This can be convenient if + you are referencing them in other rules, so you can say %SomeField instead of remembering %13. - 2. Whenever you use one of the special hledger field names (described - below), it assigns the CSV value in this position to that hledger - field. This is the quickest way to populate hledger's fields and + 2. Whenever you use one of the special hledger field names (described + below), it assigns the CSV value in this position to that hledger + field. This is the quickest way to populate hledger's fields and build a transaction. - Here's an example that says "use the 1st, 2nd and 4th fields as the - transaction's date, description and amount; name the last two fields + Here's an example that says "use the 1st, 2nd and 4th fields as the + transaction's date, description and amount; name the last two fields for later reference; and ignore the others": fields date, description, , amount, , , somefield, anotherfield @@ -2985,36 +3004,36 @@ CSV o There must be least two items in the list (at least one comma). - o Field names may not contain spaces. Spaces before/after field names + o Field names may not contain spaces. Spaces before/after field names are optional. o Field names may contain _ (underscore) or - (hyphen). - o Fields you don't care about can be given a dummy name or an empty + o Fields you don't care about can be given a dummy name or an empty name. - If the CSV contains column headings, it's convenient to use these for - your field names, suitably modified (eg lower-cased with spaces re- + If the CSV contains column headings, it's convenient to use these for + your field names, suitably modified (eg lower-cased with spaces re- placed by underscores). - Sometimes you may want to alter a CSV field name to avoid assigning to - a hledger field with the same name. Eg you could call the CSV's "bal- - ance" field balance_ to avoid directly setting hledger's balance field + Sometimes you may want to alter a CSV field name to avoid assigning to + a hledger field with the same name. Eg you could call the CSV's "bal- + ance" field balance_ to avoid directly setting hledger's balance field (and generating a balance assertion). Field assignment HLEDGERFIELD FIELDVALUE - Field assignments are the more flexible way to assign CSV values to + Field assignments are the more flexible way to assign CSV values to hledger fields. They can be used instead of or in addition to a fields list (see above). - To assign a value to a hledger field, write the field name (any of the - standard hledger field/pseudo-field names, defined below), a space, - followed by a text value on the same line. This text value may inter- - polate CSV fields, referenced by their 1-based position in the CSV - record (%N), or by the name they were given in the fields list (%CSV- - FIELD). + To assign a value to a hledger field, write the field name (any of the + standard hledger field/pseudo-field names, defined below), a space, + followed by a text value on the same line. This text value may inter- + polate CSV fields, referenced either by their 1-based position in the + CSV record (%N) or by the name they were given in the fields list + (%CSVFIELD), and regular expression match groups (\N). Some examples: @@ -3026,26 +3045,26 @@ CSV Tips: - o Interpolation strips outer whitespace (so a CSV value like " 1 " be- + o Interpolation strips outer whitespace (so a CSV value like " 1 " be- comes 1 when interpolated) (#1051). - o Interpolations always refer to a CSV field - you can't interpolate a + o Interpolations always refer to a CSV field - you can't interpolate a hledger field. (See Referencing other fields below). Field names - Note the two kinds of field names mentioned here, and used only in + Note the two kinds of field names mentioned here, and used only in hledger CSV rules files: - 1. CSV field names (CSVFIELD in these docs): you can optionally name - the CSV columns for easy reference (since hledger doesn't yet auto- + 1. CSV field names (CSVFIELD in these docs): you can optionally name + the CSV columns for easy reference (since hledger doesn't yet auto- matically recognise column headings in a CSV file), by writing arbi- trary names in a fields list, eg: fields When, What, Some_Id, Net, Total, Foo, Bar - 2. Special hledger field names (HLEDGERFIELD in these docs): you must - set at least some of these to generate the hledger transaction from - a CSV record, by writing them as the left hand side of a field as- + 2. Special hledger field names (HLEDGERFIELD in these docs): you must + set at least some of these to generate the hledger transaction from + a CSV record, by writing them as the left hand side of a field as- signment, eg: date %When @@ -3060,7 +3079,7 @@ CSV currency $ comment %Foo %Bar - Here are all the special hledger field names available, and what hap- + Here are all the special hledger field names available, and what hap- pens when you assign values to them: date field @@ -3083,7 +3102,7 @@ CSV commentN, where N is a number, sets the Nth posting's comment. - You can assign multi-line comments by writing literal \n in the code. + You can assign multi-line comments by writing literal \n in the code. A comment starting with \n will begin on a new line. Comments can contain tags, as usual. @@ -3092,98 +3111,98 @@ CSV Assigning to accountN, where N is 1 to 99, sets the account name of the Nth posting, and causes that posting to be generated. - Most often there are two postings, so you'll want to set account1 and - account2. Typically account1 is associated with the CSV file, and is - set once with a top-level assignment, while account2 is set based on + Most often there are two postings, so you'll want to set account1 and + account2. Typically account1 is associated with the CSV file, and is + set once with a top-level assignment, while account2 is set based on each transaction's description, in conditional rules. - If a posting's account name is left unset but its amount is set (see - below), a default account name will be chosen (like "expenses:unknown" + If a posting's account name is left unset but its amount is set (see + below), a default account name will be chosen (like "expenses:unknown" or "income:unknown"). amount field - There are several ways to set posting amounts from CSV, useful in dif- + There are several ways to set posting amounts from CSV, useful in dif- ferent situations. - 1. amount is the oldest and simplest. Assigning to this sets the + 1. amount is the oldest and simplest. Assigning to this sets the amount of the first and second postings. In the second posting, the - amount will be negated; also, if it has a cost attached, it will be + amount will be negated; also, if it has a cost attached, it will be converted to cost. - 2. amount-in and amount-out work exactly like the above, but should be - used when the CSV has two amount fields (such as "Debit" and - "Credit", or "Inflow" and "Outflow"). Whichever field has a non- - zero value will be used as the amount of the first and second post- + 2. amount-in and amount-out work exactly like the above, but should be + used when the CSV has two amount fields (such as "Debit" and + "Credit", or "Inflow" and "Outflow"). Whichever field has a non- + zero value will be used as the amount of the first and second post- ings. Here are some tips to avoid confusion: - o It's not "amount-in for posting 1 and amount-out for posting 2", - it is "extract a single amount from the amount-in or amount-out + o It's not "amount-in for posting 1 and amount-out for posting 2", + it is "extract a single amount from the amount-in or amount-out field, and use that for posting 1 and (negated) for posting 2". - o Don't use both amount and amount-in/amount-out in the same rules + o Don't use both amount and amount-in/amount-out in the same rules file; choose based on whether the amount is in a single CSV field or spread across two fields. - o In each record, at most one of the two CSV fields should contain - a non-zero amount; the other field must contain a zero or noth- + o In each record, at most one of the two CSV fields should contain + a non-zero amount; the other field must contain a zero or noth- ing. - o hledger assumes both CSV fields contain unsigned numbers, and it + o hledger assumes both CSV fields contain unsigned numbers, and it automatically negates the amount-out values. - o If the data doesn't fit these requirements, you'll probably need + o If the data doesn't fit these requirements, you'll probably need an if rule (see below). 3. amountN (where N is a number from 1 to 99) sets the amount of only a - single posting: the Nth posting in the transaction. You'll usually - need at least two such assignments to make a balanced transaction. + single posting: the Nth posting in the transaction. You'll usually + need at least two such assignments to make a balanced transaction. You can also generate more than two postings, to represent more com- - plex transactions. The posting numbers don't have to be consecu- - tive; with if rules, higher posting numbers can be useful to ensure + plex transactions. The posting numbers don't have to be consecu- + tive; with if rules, higher posting numbers can be useful to ensure a certain order of postings. - 4. amountN-in and amountN-out work exactly like the above, but should - be used when the CSV has two amount fields. This is analogous to + 4. amountN-in and amountN-out work exactly like the above, but should + be used when the CSV has two amount fields. This is analogous to amount-in and amount-out, and those tips also apply here. 5. Remember that a fields list can also do assignments. So in a fields - list if you name a CSV field "amount", that counts as assigning to - amount. (If you don't want that, call it something else in the + list if you name a CSV field "amount", that counts as assigning to + amount. (If you don't want that, call it something else in the fields list, like "amount_".) - 6. The above don't handle every situation; if you need more flexibil- + 6. The above don't handle every situation; if you need more flexibil- ity, use an if rule to set amounts conditionally. See "Working with - CSV > Setting amounts" below for more on this and on amount-setting + CSV > Setting amounts" below for more on this and on amount-setting generally. currency field - currency sets a currency symbol, to be prepended to all postings' - amounts. You can use this if the CSV amounts do not have a currency + currency sets a currency symbol, to be prepended to all postings' + amounts. You can use this if the CSV amounts do not have a currency symbol, eg if it is in a separate column. currencyN prepends a currency symbol to just the Nth posting's amount. balance field - balanceN sets a balance assertion amount (or if the posting amount is + balanceN sets a balance assertion amount (or if the posting amount is left empty, a balance assignment) on posting N. balance is a compatibility spelling for hledger <1.17; it is equivalent to balance1. - You can adjust the type of assertion/assignment with the balance-type + You can adjust the type of assertion/assignment with the balance-type rule (see below). See Tips below for more about setting amounts and currency. if block - Rules can be applied conditionally, depending on patterns in the CSV - data. This allows flexibility; in particular, it is how you can cate- - gorise transactions, selecting an appropriate account name based on - their description (for example). There are two ways to write condi- - tional rules: "if blocks", described here, and "if tables", described + Rules can be applied conditionally, depending on patterns in the CSV + data. This allows flexibility; in particular, it is how you can cate- + gorise transactions, selecting an appropriate account name based on + their description (for example). There are two ways to write condi- + tional rules: "if blocks", described here, and "if tables", described below. - An if block is the word if and one or more "matcher" expressions (can + An if block is the word if and one or more "matcher" expressions (can be a word or phrase), one per line, starting either on the same or next line; followed by one or more indented rules. Eg, @@ -3199,11 +3218,11 @@ CSV RULE RULE - If any of the matchers succeeds, all of the indented rules will be ap- - plied. They are usually field assignments, but the following special + If any of the matchers succeeds, all of the indented rules will be ap- + plied. They are usually field assignments, but the following special rules may also be used within an if block: - o skip - skips the matched CSV record (generating no transaction from + o skip - skips the matched CSV record (generating no transaction from it) o end - skips the rest of the current CSV file. @@ -3229,26 +3248,26 @@ CSV Matchers There are two kinds: - 1. A record matcher is a word or single-line text fragment or regular - expression (REGEX), which hledger will try to match case-insensi- + 1. A record matcher is a word or single-line text fragment or regular + expression (REGEX), which hledger will try to match case-insensi- tively anywhere within the CSV record. Eg: whole foods - 2. A field matcher is preceded with a percent sign and CSV field name - (%CSVFIELD REGEX). hledger will try to match these just within the + 2. A field matcher is preceded with a percent sign and CSV field name + (%CSVFIELD REGEX). hledger will try to match these just within the named CSV field. Eg: %date 2023 - The regular expression is (as usual in hledger) a POSIX extended regu- - lar expression, that also supports GNU word boundaries (\b, \B, \<, - \>), and nothing else. If you have trouble, see "Regular expressions" + The regular expression is (as usual in hledger) a POSIX extended regu- + lar expression, that also supports GNU word boundaries (\b, \B, \<, + \>), and nothing else. If you have trouble, see "Regular expressions" in the hledger manual (https://hledger.org/hledger.html#regular-expres- sions). With record matchers, it's important to know that the record matched is - not the original CSV record, but a modified one: separators will be - converted to commas, and enclosing double quotes (but not enclosing - whitespace) are removed. So for example, when reading an SSV file, if + not the original CSV record, but a modified one: separators will be + converted to commas, and enclosing double quotes (but not enclosing + whitespace) are removed. So for example, when reading an SSV file, if the original record was: 2023-01-01; "Acme, Inc."; 1,000 @@ -3261,14 +3280,36 @@ CSV o By default they are OR'd (any one of them can match) - o When a matcher is preceded by ampersand (&) it will be AND'ed with + o When a matcher is preceded by ampersand (&) it will be AND'ed with the previous matcher (both of them must match). - There's not yet an easy syntax to negate a matcher. + When a matcher is preceded by an exclamation mark (!), the matcher will + be negated, ie it will exclude CSV records that match. + + Match groups + Matchers can define match groups: parenthesised portions of the regular + expression which are available for reference in field assignments. + Groups are enclosed in regular parentheses (( and )) and can be nested. + Each group is available in field assignments using the token \N, where + N is an index into the match groups for this conditional block (e.g. + \1, \2, etc.). + + Example: Warp credit card payment postings to the beginning of the + billing period (Month start), to match how they are presented in state- + ments, using posting dates: + + if %date (....-..)-.. + comment2 date:\1-01 + + Another example: Read the expense account from the CSV field, but throw + away a prefix: + + if %account1 liabilities:family:(expenses:.*) + account1 \1 if table - "if tables" are an alternative to if blocks; they can express many - matchers and field assignments in a more compact tabular format, like + "if tables" are an alternative to if blocks; they can express many + matchers and field assignments in a more compact tabular format, like this: if,HLEDGERFIELD1,HLEDGERFIELD2,... @@ -3277,18 +3318,21 @@ CSV MATCHERC,VALUE1,VALUE2,... - The first character after if is taken to be the separator for the rest - of the table. It should be a non-alphanumeric character like , or | - that does not appear anywhere else in the table. (Note: it is unre- - lated to the CSV file's separator.) Whitespace can be used in the - matcher lines for readability, but not in the if line currently. The - table must be terminated by an empty line (or end of file). Each line - must contain the same number of separators; empty values are allowed. + The first character after if is taken to be this if table's field sepa- + rator. It is unrelated to the separator used in the CSV file. It + should be a non-alphanumeric character like , or | that does not appear + anywhere else in the table (it should not be used in field names or + matchers or values, and it cannot be escaped with a backslash). - The above means: try all of the matchers; whenever a matcher succeeds, - assign all of the values on that line to the corresponding hledger - fields; later lines can overrider earlier ones. It is equivalent to - this sequence of if blocks: + Each line must contain the same number of separators; empty values are + allowed. Whitespace can be used in the matcher lines for readability + (but not in the if line, currently). The table must be terminated by + an empty line (or end of file). + + An if table like the above is interpreted as follows: try all of the + matchers; whenever a matcher succeeds, assign all of the values on that + line to the corresponding hledger fields; later lines can overrider + earlier ones. It is equivalent to this sequence of if blocks: if MATCHERA HLEDGERFIELD1 VALUE1 @@ -3314,10 +3358,10 @@ CSV balance-type Balance assertions generated by assigning to balanceN are of the simple - = type by default, which is a single-commodity, subaccount-excluding + = type by default, which is a single-commodity, subaccount-excluding assertion. You may find the subaccount-including variants more useful, - eg if you have created some virtual subaccounts of checking to help - with budgeting. You can select a different type of assertion with the + eg if you have created some virtual subaccounts of checking to help + with budgeting. You can select a different type of assertion with the balance-type rule: # balance assertions will consider all commodities and all subaccounts @@ -3333,9 +3377,9 @@ CSV include include RULESFILE - This includes the contents of another CSV rules file at this point. - RULESFILE is an absolute file path or a path relative to the current - file's directory. This can be useful for sharing common rules between + This includes the contents of another CSV rules file at this point. + RULESFILE is an absolute file path or a path relative to the current + file's directory. This can be useful for sharing common rules between several rules files, eg: # someaccount.csv.rules @@ -3352,42 +3396,42 @@ CSV Some tips: Rapid feedback - It's a good idea to get rapid feedback while creating/troubleshooting + It's a good idea to get rapid feedback while creating/troubleshooting CSV rules. Here's a good way, using entr from eradman.com/entrproject: $ ls foo.csv* | entr bash -c 'echo ----; hledger -f foo.csv print desc:SOMEDESC' - A desc: query (eg) is used to select just one, or a few, transactions - of interest. "bash -c" is used to run multiple commands, so we can - echo a separator each time the command re-runs, making it easier to + A desc: query (eg) is used to select just one, or a few, transactions + of interest. "bash -c" is used to run multiple commands, so we can + echo a separator each time the command re-runs, making it easier to read the output. Valid CSV - Note that hledger will only accept valid CSV conforming to RFC 4180, + Note that hledger will only accept valid CSV conforming to RFC 4180, and equivalent SSV and TSV formats (like RFC 4180 but with semicolon or tab as separators). This means, eg: o Values may be enclosed in double quotes, or not. Enclosing in single quotes is not allowed. (Eg 'A','B' is rejected.) - o When values are enclosed in double quotes, spaces outside the quotes + o When values are enclosed in double quotes, spaces outside the quotes are not allowed. (Eg "A", "B" is rejected.) - o When values are not enclosed in quotes, they may not contain double + o When values are not enclosed in quotes, they may not contain double quotes. (Eg A"A, B is rejected.) - If your CSV/SSV/TSV is not valid in this sense, you'll need to trans- - form it before reading with hledger. Try using sed, or a more permis- + If your CSV/SSV/TSV is not valid in this sense, you'll need to trans- + form it before reading with hledger. Try using sed, or a more permis- sive CSV parser like python's csv lib. File Extension - To help hledger choose the CSV file reader and show the right error - messages (and choose the right field separator character by default), - it's best if CSV/SSV/TSV files are named with a .csv, .ssv or .tsv + To help hledger choose the CSV file reader and show the right error + messages (and choose the right field separator character by default), + it's best if CSV/SSV/TSV files are named with a .csv, .ssv or .tsv filename extension. (More about this at Data formats.) - When reading files with the "wrong" extension, you can ensure the CSV - reader (and the default field separator) by prefixing the file path + When reading files with the "wrong" extension, you can ensure the CSV + reader (and the default field separator) by prefixing the file path with csv:, ssv: or tsv:: Eg: $ hledger -f ssv:foo.dat print @@ -3396,29 +3440,29 @@ CSV if needed. Reading CSV from standard input - You'll need the file format prefix when reading CSV from stdin also, + You'll need the file format prefix when reading CSV from stdin also, since hledger assumes journal format by default. Eg: $ cat foo.dat | hledger -f ssv:- print Reading multiple CSV files - If you use multiple -f options to read multiple CSV files at once, - hledger will look for a correspondingly-named rules file for each CSV - file. But if you use the --rules-file option, that rules file will be + If you use multiple -f options to read multiple CSV files at once, + hledger will look for a correspondingly-named rules file for each CSV + file. But if you use the --rules-file option, that rules file will be used for all the CSV files. Reading files specified by rule Instead of specifying a CSV file in the command line, you can specify a - rules file, as in hledger -f foo.csv.rules CMD. By default this will - read data from foo.csv in the same directory, but you can add a source - rule to specify a different data file, perhaps located in your web + rules file, as in hledger -f foo.csv.rules CMD. By default this will + read data from foo.csv in the same directory, but you can add a source + rule to specify a different data file, perhaps located in your web browser's download directory. This feature was added in hledger 1.30, so you won't see it in most CSV - rules examples. But it helps remove some of the busywork of managing + rules examples. But it helps remove some of the busywork of managing CSV downloads. Most of your financial institutions's default CSV file- - names are different and can be recognised by a glob pattern. So you - can put a rule like source Checking1*.csv in foo-checking.csv.rules, + names are different and can be recognised by a glob pattern. So you + can put a rule like source Checking1*.csv in foo-checking.csv.rules, and then periodically follow a workflow like: 1. Download CSV from Foo's website, using your browser's defaults @@ -3426,45 +3470,45 @@ CSV 2. Run hledger import foo-checking.csv.rules to import any new transac- tions - After import, you can: discard the CSV, or leave it where it is for a - while, or move it into your archives, as you prefer. If you do noth- - ing, next time your browser will save something like Checking1-2.csv, - and hledger will use that because of the * wild card and because it is + After import, you can: discard the CSV, or leave it where it is for a + while, or move it into your archives, as you prefer. If you do noth- + ing, next time your browser will save something like Checking1-2.csv, + and hledger will use that because of the * wild card and because it is the most recent. Valid transactions After reading a CSV file, hledger post-processes and validates the gen- erated journal entries as it would for a journal file - balancing them, - applying balance assignments, and canonicalising amount styles. Any - errors at this stage will be reported in the usual way, displaying the + applying balance assignments, and canonicalising amount styles. Any + errors at this stage will be reported in the usual way, displaying the problem entry. There is one exception: balance assertions, if you have generated them, - will not be checked, since normally these will work only when the CSV - data is part of the main journal. If you do need to check balance as- + will not be checked, since normally these will work only when the CSV + data is part of the main journal. If you do need to check balance as- sertions generated from CSV right away, pipe into another hledger: $ hledger -f file.csv print | hledger -f- print Deduplicating, importing - When you download a CSV file periodically, eg to get your latest bank - transactions, the new file may overlap with the old one, containing + When you download a CSV file periodically, eg to get your latest bank + transactions, the new file may overlap with the old one, containing some of the same records. The import command will (a) detect the new transactions, and (b) append just those transactions to your main journal. It is idempotent, so you - don't have to remember how many times you ran it or with which version - of the CSV. (It keeps state in a hidden .latest.FILE.csv file.) This + don't have to remember how many times you ran it or with which version + of the CSV. (It keeps state in a hidden .latest.FILE.csv file.) This is the easiest way to import CSV data. Eg: # download the latest CSV files, then run this command. # Note, no -f flags needed here. $ hledger import *.csv [--dry] - This method works for most CSV files. (Where records have a stable + This method works for most CSV files. (Where records have a stable chronological order, and new records appear only at the new end.) - A number of other tools and workflows, hledger-specific and otherwise, + A number of other tools and workflows, hledger-specific and otherwise, exist for converting, deduplicating, classifying and managing CSV data. See: @@ -3473,16 +3517,16 @@ CSV o https://plaintextaccounting.org -> data import/conversion Setting amounts - Continuing from amount field above, here are more tips for amount-set- + Continuing from amount field above, here are more tips for amount-set- ting: 1. If the amount is in a single CSV field: a. If its sign indicates direction of flow: - Assign it to amountN, to set the Nth posting's amount. N is usu- + Assign it to amountN, to set the Nth posting's amount. N is usu- ally 1 or 2 but can go up to 99. b. If another field indicates direction of flow: - Use one or more conditional rules to set the appropriate amount + Use one or more conditional rules to set the appropriate amount sign. Eg: # assume a withdrawal unless Type contains "deposit": @@ -3490,15 +3534,15 @@ CSV if %Type deposit amount1 %Amount - 2. If the amount is in two CSV fields (such as Debit and Credit, or In + 2. If the amount is in two CSV fields (such as Debit and Credit, or In and Out): a. If both fields are unsigned: - Assign one field to amountN-in and the other to amountN-out. - hledger will automatically negate the "out" field, and will use + Assign one field to amountN-in and the other to amountN-out. + hledger will automatically negate the "out" field, and will use whichever field value is non-zero as posting N's amount. b. If either field is signed: - You will probably need to override hledger's sign for one or the + You will probably need to override hledger's sign for one or the other field, as in the following example: # Negate the -out value, but only if it is not empty: @@ -3506,12 +3550,12 @@ CSV if %amount1-out [1-9] amount1-out -%amount1-out - c. If both fields can contain a non-zero value (or both can be + c. If both fields can contain a non-zero value (or both can be empty): The -in/-out rules normally choose the value which is non-zero/non- empty. Some value pairs can be ambiguous, such as 1 and none. For - such cases, use conditional rules to help select the amount. Eg, - to handle the above you could select the value containing non-zero + such cases, use conditional rules to help select the amount. Eg, + to handle the above you could select the value containing non-zero digits: fields date, description, in, out @@ -3524,8 +3568,8 @@ CSV Use the unnumbered amount (or amount-in and amount-out) syntax. 4. If the CSV has only balance amounts, not transaction amounts: - Assign to balanceN, to set a balance assignment on the Nth posting, - causing the posting's amount to be calculated automatically. balance + Assign to balanceN, to set a balance assignment on the Nth posting, + causing the posting's amount to be calculated automatically. balance with no number is equivalent to balance1. In this situation hledger is more likely to guess the wrong default account name, so you may need to set that explicitly. @@ -3541,20 +3585,20 @@ CSV o If an amount value is parenthesised: it will be de-parenthesised and sign-flipped: (AMT) becomes -AMT - o If an amount value has two minus signs (or two sets of parentheses, + o If an amount value has two minus signs (or two sets of parentheses, or a minus sign and parentheses): they cancel out and will be removed: --AMT or -(AMT) becomes AMT - o If an amount value contains just a sign (or just a set of parenthe- + o If an amount value contains just a sign (or just a set of parenthe- ses): - that is removed, making it an empty value. "+" or "-" or "()" becomes + that is removed, making it an empty value. "+" or "-" or "()" becomes "". - It's not possible (without preprocessing the CSV) to set an amount to + It's not possible (without preprocessing the CSV) to set an amount to its absolute value, ie discard its sign. Setting currency/commodity - If the currency/commodity symbol is included in the CSV's amount + If the currency/commodity symbol is included in the CSV's amount field(s): 2023-01-01,foo,$123.00 @@ -3573,7 +3617,7 @@ CSV 2023-01-01,foo,USD,123.00 You can assign that to the currency pseudo-field, which has the special - effect of prepending itself to every amount in the transaction (on the + effect of prepending itself to every amount in the transaction (on the left, with no separating space): fields date,description,currency,amount @@ -3582,7 +3626,7 @@ CSV expenses:unknown USD123.00 income:unknown USD-123.00 - Or, you can use a field assignment to construct the amount yourself, + Or, you can use a field assignment to construct the amount yourself, with more control. Eg to put the symbol on the right, and separated by a space: @@ -3593,7 +3637,7 @@ CSV expenses:unknown 123.00 USD income:unknown -123.00 USD - Note we used a temporary field name (cur) that is not currency - that + Note we used a temporary field name (cur) that is not currency - that would trigger the prepending effect, which we don't want here. Amount decimal places @@ -3601,13 +3645,13 @@ CSV amount1 influence commodity display styles, such as the number of deci- mal places displayed in reports. - The original amounts as written in the CSV file do not affect display + The original amounts as written in the CSV file do not affect display style (because we don't yet reliably know their commodity). Referencing other fields - In field assignments, you can interpolate only CSV fields, not hledger - fields. In the example below, there's both a CSV field and a hledger - field named amount1, but %amount1 always means the CSV field, not the + In field assignments, you can interpolate only CSV fields, not hledger + fields. In the example below, there's both a CSV field and a hledger + field named amount1, but %amount1 always means the CSV field, not the hledger field: # Name the third CSV field "amount1" @@ -3619,7 +3663,7 @@ CSV # Set comment to the CSV amount1 (not the amount1 assigned above) comment %amount1 - Here, since there's no CSV amount1 field, %amount1 will produce a lit- + Here, since there's no CSV amount1 field, %amount1 will produce a lit- eral "amount1": fields date,description,csvamount @@ -3627,7 +3671,7 @@ CSV # Can't interpolate amount1 here comment %amount1 - When there are multiple field assignments to the same hledger field, + When there are multiple field assignments to the same hledger field, only the last one takes effect. Here, comment's value will be be B, or C if "something" is matched, but never A: @@ -3637,14 +3681,14 @@ CSV comment C How CSV rules are evaluated - Here's how to think of CSV rules being evaluated (if you really need + Here's how to think of CSV rules being evaluated (if you really need to). First, - o include - all includes are inlined, from top to bottom, depth first. - (At each include point the file is inlined and scanned for further + o include - all includes are inlined, from top to bottom, depth first. + (At each include point the file is inlined and scanned for further includes, recursively, before proceeding.) - Then "global" rules are evaluated, top to bottom. If a rule is re- + Then "global" rules are evaluated, top to bottom. If a rule is re- peated, the last one wins: o skip (at top level) @@ -3658,30 +3702,30 @@ CSV Then for each CSV record in turn: - o test all if blocks. If any of them contain a end rule, skip all re- - maining CSV records. Otherwise if any of them contain a skip rule, - skip that many CSV records. If there are multiple matched skip + o test all if blocks. If any of them contain a end rule, skip all re- + maining CSV records. Otherwise if any of them contain a skip rule, + skip that many CSV records. If there are multiple matched skip rules, the first one wins. - o collect all field assignments at top level and in matched if blocks. - When there are multiple assignments for a field, keep only the last + o collect all field assignments at top level and in matched if blocks. + When there are multiple assignments for a field, keep only the last one. - o compute a value for each hledger field - either the one that was as- + o compute a value for each hledger field - either the one that was as- signed to it (and interpolate the %CSVFIELD references), or a default o generate a hledger transaction (journal entry) from these values. - This is all part of the CSV reader, one of several readers hledger can - use to parse input files. When all files have been read successfully, - the transactions are passed as input to whichever hledger command the + This is all part of the CSV reader, one of several readers hledger can + use to parse input files. When all files have been read successfully, + the transactions are passed as input to whichever hledger command the user specified. Well factored rules - Some things than can help reduce duplication and complexity in rules + Some things than can help reduce duplication and complexity in rules files: - o Extracting common rules usable with multiple CSV files into a com- + o Extracting common rules usable with multiple CSV files into a com- mon.rules, and adding include common.rules to each CSV's rules file. o Splitting if blocks into smaller if blocks, extracting the frequently @@ -3689,8 +3733,8 @@ CSV CSV rules examples Bank of Ireland - Here's a CSV with two amount fields (Debit and Credit), and a balance - field, which we can use to add balance assertions, which is not neces- + Here's a CSV with two amount fields (Debit and Credit), and a balance + field, which we can use to add balance assertions, which is not neces- sary but provides extra error checking: Date,Details,Debit,Credit,Balance @@ -3732,13 +3776,13 @@ CSV assets:bank:boi:checking EUR-5.0 = EUR126.0 expenses:unknown EUR5.0 - The balance assertions don't raise an error above, because we're read- - ing directly from CSV, but they will be checked if these entries are + The balance assertions don't raise an error above, because we're read- + ing directly from CSV, but they will be checked if these entries are imported into a journal file. Coinbase - A simple example with some CSV from Coinbase. The spot price is - recorded using cost notation. The legacy amount field name conve- + A simple example with some CSV from Coinbase. The spot price is + recorded using cost notation. The legacy amount field name conve- niently sets amount 2 (posting 2's amount) to the total cost. # Timestamp,Transaction Type,Asset,Quantity Transacted,Spot Price Currency,Spot Price at Transaction,Subtotal,Total (inclusive of fees and/or spread),Fees and/or Spread,Notes @@ -3760,7 +3804,7 @@ CSV Amazon Here we convert amazon.com order history, and use an if block to gener- - ate a third posting if there's a fee. (In practice you'd probably get + ate a third posting if there's a fee. (In practice you'd probably get this data from your bank instead, but it's an example.) "Date","Type","To/From","Name","Status","Amount","Fees","Transaction ID" @@ -3812,7 +3856,7 @@ CSV expenses:fees $1.00 Paypal - Here's a real-world rules file for (customised) Paypal CSV, with some + Here's a real-world rules file for (customised) Paypal CSV, with some Paypal-specific rules, and a second rules file included: "Date","Time","TimeZone","Name","Type","Status","Currency","Gross","Fee","Net","From Email Address","To Email Address","Transaction ID","Item Title","Item ID","Reference Txn ID","Receipt ID","Balance","Note" @@ -3963,12 +4007,12 @@ CSV Timeclock The time logging format of timeclock.el, as read by hledger. - hledger can read time logs in timeclock format. As with Ledger, these + hledger can read time logs in timeclock format. As with Ledger, these are (a subset of) timeclock.el's format, containing clock-in and clock- - out entries as in the example below. The date is a simple date. The - time format is HH:MM[:SS][+-ZZZZ]. Seconds and timezone are optional. + out entries as in the example below. The date is a simple date. The + time format is HH:MM[:SS][+-ZZZZ]. Seconds and timezone are optional. The timezone, if present, must be four digits and is ignored (currently - the time is always interpreted as a local time). Lines beginning with + the time is always interpreted as a local time). Lines beginning with # or ; or *, and blank lines, are ignored. i 2015/03/30 09:00:00 some account optional description after 2 spaces ; optional comment, tags: @@ -3976,9 +4020,9 @@ Timeclock i 2015/03/31 22:21:45 another:account o 2015/04/01 02:00:34 - hledger treats each clock-in/clock-out pair as a transaction posting - some number of hours to an account. Or if the session spans more than - one day, it is split into several transactions, one for each day. For + hledger treats each clock-in/clock-out pair as a transaction posting + some number of hours to an account. Or if the session spans more than + one day, it is split into several transactions, one for each day. For the above time log, hledger print generates these journal entries: $ hledger -f t.timeclock print @@ -3999,26 +4043,26 @@ Timeclock To generate time logs, ie to clock in and clock out, you could: - o use emacs and the built-in timeclock.el, or the extended timeclock- + o use emacs and the built-in timeclock.el, or the extended timeclock- x.el and perhaps the extras in ledgerutils.el o at the command line, use these bash aliases: shell alias ti="echo - i `date '+%Y-%m-%d %H:%M:%S'` \$* >>$TIMELOG" alias to="echo o + i `date '+%Y-%m-%d %H:%M:%S'` \$* >>$TIMELOG" alias to="echo o `date '+%Y-%m-%d %H:%M:%S'` >>$TIMELOG" o or use the old ti and to scripts in the ledger 2.x repository. These - rely on a "timeclock" executable which I think is just the ledger 2 + rely on a "timeclock" executable which I think is just the ledger 2 executable renamed. Timedot - timedot format is hledger's human-friendly time logging format. Com- + timedot format is hledger's human-friendly time logging format. Com- pared to timeclock format, it is o convenient for quick, approximate, and retroactive time logging o readable: you can see at a glance where time was spent. - A timedot file contains a series of day entries, which might look like + A timedot file contains a series of day entries, which might look like this: 2023-05-01 @@ -4027,9 +4071,9 @@ Timedot per:admin:finance hledger reads this as a transaction on this day with three (unbalanced) - postings, where each dot represents "0.25". No commodity is assumed, - but normally we interpret it as hours, with each dot representing a - quarter-hour. It's convenient, though not required, to group the dots + postings, where each dot represents "0.25". No commodity is assumed, + but normally we interpret it as hours, with each dot representing a + quarter-hour. It's convenient, though not required, to group the dots in fours for easy reading. $ hledger -f a.timedot print # .timedot file extension (or timedot: prefix) is required @@ -4038,52 +4082,52 @@ Timedot (fos:hledger:timedot) 0.50 ; half an hour (per:admin:finance) 0 - A transaction begins with a non-indented simple date (Y-M-D, Y/M/D, or - Y.M.D). It can optionally be preceded by one or more stars and a + A transaction begins with a non-indented simple date (Y-M-D, Y/M/D, or + Y.M.D). It can optionally be preceded by one or more stars and a space, for Emacs org mode compatibility. It can optionally be followed - on the same line by a transaction description, and/or a transaction + on the same line by a transaction description, and/or a transaction comment following a semicolon. After the date line are zero or more time postings, consisting of: - o an account name - any hledger-style account name, optionally hierar- + o an account name - any hledger-style account name, optionally hierar- chical, optionally indented. - o two or more spaces - a field separator, required if there is an + o two or more spaces - a field separator, required if there is an amount (as in journal format). - o an optional timedot amount - dots representing quarter hours, or a + o an optional timedot amount - dots representing quarter hours, or a number representing hours, optionally with a unit suffix. o an optional posting comment following a semicolon. Timedot amounts can be: - o dots: zero or more period characters (.), each representing 0.25. + o dots: zero or more period characters (.), each representing 0.25. Spaces are ignored and can be used for grouping. Eg: .... .. o or a number. Eg: 1.5 - o or a number immediately followed by a unit symbol s, m, h, d, w, mo, - or y. These are interpreted as seconds, minutes, hours, days weeks, + o or a number immediately followed by a unit symbol s, m, h, d, w, mo, + or y. These are interpreted as seconds, minutes, hours, days weeks, months or years, and converted to hours, assuming: 60s = 1m, 60m = 1h, 24h = 1d, 7d = 1w, 30d = 1mo, 365d = 1y. Eg 90m is parsed as 1.5. - There is some added flexibility to help with keeping time log data in + There is some added flexibility to help with keeping time log data in the same file as your notes, todo lists, etc.: o Blank lines and lines beginning with # or ; are ignored. o Before the first date line, lines beginning with * are ignored. - o From the first date line onward, one or more *'s followed by a space - at beginning of lines (ie, the headline prefix used by Emacs Org - mode) is ignored. This means the time log can be kept under an Org - headline, and date lines or time transaction lines can be Org head- + o From the first date line onward, one or more *'s followed by a space + at beginning of lines (ie, the headline prefix used by Emacs Org + mode) is ignored. This means the time log can be kept under an Org + headline, and date lines or time transaction lines can be Org head- lines. - o Lines not ending with a double-space and amount are parsed as post- + o Lines not ending with a double-space and amount are parsed as post- ings with zero amount. Note hledger's register reports hide these by default (add -E to see them). @@ -4165,42 +4209,89 @@ Timedot A sample.timedot file. PART 3: REPORTING CONCEPTS +Amount formatting, parseability + If you're wondering why your print report sometimes shows trailing dec- + imal marks, even when there are no decimal digits; it does this to dis- + ambiguate ambiguous amounts (amounts which have one digit group mark + and no decimal digits), allowing them to be re-parsed reliably. + + More generally: hledger output falls into three rough categories, which + format amounts a little bit differently to suit different consumers: + + 1. "hledger-readable output" - should be readable by hledger (and by + humans) + + o This is produced by reports that show full journal entries: print, + import, close, rewrite etc. + + o It shows amounts with their original journal precisions, which may + not be consistent. + + o It adds a trailing decimal mark when needed to avoid showing ambigu- + ous amounts. + + o It can be parsed reliably (by hledger and ledger2beancount at least, + but perhaps not by Ledger..) + + 2. "human-readable output" - usually for humans + + o This is produced by all other reports. + + o It shows amounts with standard display precisions, which will be con- + sistent within each commodity. + + o It shows ambiguous amounts unmodified. + + o It can be parsed reliably in the context of a known report (when you + know decimals are consistently not being shown, you can assume a sin- + gle mark is a digit group mark). + + 3. "machine-readable output" - usually for other software + + o This is produced by all reports when an output format like csv, tsv, + json, or sql is selected. + + o It shows amounts as 1 or 2 do, but without digit group marks. + + o It can be parsed reliably (if needed, the decimal mark can be changed + with -c/--commodity-style). + Time periods Report start & end date By default, most hledger reports will show the full span of time repre- - sented by the journal. The report start date will be the earliest + sented by the journal. The report start date will be the earliest transaction or posting date, and the report end date will be the latest transaction, posting, or market price date. - Often you will want to see a shorter time span, such as the current - month. You can specify a start and/or end date using -b/--begin, + Often you will want to see a shorter time span, such as the current + month. You can specify a start and/or end date using -b/--begin, -e/--end, -p/--period or a date: query (described below). All of these accept the smart date syntax (below). Some notes: - o End dates are exclusive, as in Ledger, so you should write the date + o End dates are exclusive, as in Ledger, so you should write the date after the last day you want to see in the report. - o As noted in reporting options: among start/end dates specified with + o As noted in reporting options: among start/end dates specified with options, the last (i.e. right-most) option takes precedence. - o The effective report start and end dates are the intersection of the - start/end dates from options and that from date: queries. That is, - date:2019-01 date:2019 -p'2000 to 2030' yields January 2019, the + o The effective report start and end dates are the intersection of the + start/end dates from options and that from date: queries. That is, + date:2019-01 date:2019 -p'2000 to 2030' yields January 2019, the smallest common time span. - o In some cases a report interval will adjust start/end dates to fall + o In some cases a report interval will adjust start/end dates to fall on interval boundaries (see below). Examples: -b 2016/3/17 begin on St. Patrick's day 2016 - -e 12/1 end at the start of december 1st of the current year + -e 12/1 end at the start of december 1st of the current year (11/30 will be the last date included) -b thismonth all transactions on or after the 1st of the current month -p thismonth all transactions in the current month - date:2016/3/17.. the above written as queries instead (.. can also be re- + date:2016/3/17.. the above written as queries instead (.. can also be re- placed with -) date:..12/1 date:thismonth.. @@ -4208,11 +4299,11 @@ Time periods Smart dates hledger's user interfaces accept a "smart date" syntax for added conve- - nience. Smart dates optionally can be relative to today's date, be - written with english words, and have less-significant parts omitted + nience. Smart dates optionally can be relative to today's date, be + written with english words, and have less-significant parts omitted (missing parts are inferred as 1). Some examples: - 2004/10/1, 2004-01-01, exact date, several separators allowed. Year + 2004/10/1, 2004-01-01, exact date, several separators allowed. Year 2004.9.1 is 4+ digits, month is 1-12, day is 1-31 2004 start of year 2004/10 start of month @@ -4236,26 +4327,26 @@ Time periods 20181201 8 digit YYYYMMDD with valid year month and day 201812 6 digit YYYYMM with valid year and month - Some counterexamples - malformed digit sequences might give surprising + Some counterexamples - malformed digit sequences might give surprising results: - 201813 6 digits with an invalid month is parsed as start of + 201813 6 digits with an invalid month is parsed as start of 6-digit year - 20181301 8 digits with an invalid month is parsed as start of + 20181301 8 digits with an invalid month is parsed as start of 8-digit year 20181232 8 digits with an invalid day gives an error 201801012 9+ digits beginning with a valid YYYYMMDD gives an error - "Today's date" can be overridden with the --today option, in case it's + "Today's date" can be overridden with the --today option, in case it's needed for testing or for recreating old reports. (Except for periodic transaction rules, which are not affected by --today.) Report intervals - A report interval can be specified so that reports like register, bal- + A report interval can be specified so that reports like register, bal- ance or activity become multi-period, showing each subperiod as a sepa- rate row or column. - The following standard intervals can be enabled with command-line + The following standard intervals can be enabled with command-line flags: o -D/--daily @@ -4268,47 +4359,47 @@ Time periods o -Y/--yearly - More complex intervals can be specified using -p/--period, described + More complex intervals can be specified using -p/--period, described below. Date adjustment - When there is a report interval (other than daily), report start/end - dates which have been inferred, eg from the journal, are automatically - adjusted to natural period boundaries. This is convenient for produc- + When there is a report interval (other than daily), report start/end + dates which have been inferred, eg from the journal, are automatically + adjusted to natural period boundaries. This is convenient for produc- ing simple periodic reports. More precisely: - o an inferred start date will be adjusted earlier if needed to fall on + o an inferred start date will be adjusted earlier if needed to fall on a natural period boundary - o an inferred end date will be adjusted later if needed to make the + o an inferred end date will be adjusted later if needed to make the last period the same length as the others. By contrast, start/end dates which have been specified explicitly, with - -b, -e, -p or date:, will not be adjusted (since hledger 1.29). This - makes it possible to specify non-standard report periods, but it also - means that if you are specifying a start date, you should pick one - that's on a period boundary if you want to see simple report period + -b, -e, -p or date:, will not be adjusted (since hledger 1.29). This + makes it possible to specify non-standard report periods, but it also + means that if you are specifying a start date, you should pick one + that's on a period boundary if you want to see simple report period headings. Period expressions - The -p/--period option specifies a period expression, which is a com- + The -p/--period option specifies a period expression, which is a com- pact way of expressing a start date, end date, and/or report interval. - Here's a period expression with a start and end date (specifying the + Here's a period expression with a start and end date (specifying the first quarter of 2009): -p "from 2009/1/1 to 2009/4/1" - Several keywords like "from" and "to" are supported for readability; - these are optional. "to" can also be written as ".." or "-". The - spaces are also optional, as long as you don't run two dates together. + Several keywords like "from" and "to" are supported for readability; + these are optional. "to" can also be written as ".." or "-". The + spaces are also optional, as long as you don't run two dates together. So the following are equivalent to the above: -p "2009/1/1 2009/4/1" -p2009/1/1to2009/4/1 -p2009/1/1..2009/4/1 - Dates are smart dates, so if the current year is 2009, these are also + Dates are smart dates, so if the current year is 2009, these are also equivalent to the above: -p "1/1 4/1" @@ -4320,28 +4411,28 @@ Time periods -p "from 2009/1/1" everything after january 1, 2009 - -p "since 2009/1" the same, since is a syn- + -p "since 2009/1" the same, since is a syn- onym -p "from 2009" the same - -p "to 2009" everything before january + -p "to 2009" everything before january 1, 2009 You can also specify a period by writing a single partial or full date: -p "2009" the year 2009; equivalent to "2009/1/1 to 2010/1/1" - -p "2009/1" the month of january 2009; equivalent to "2009/1/1 to + -p "2009/1" the month of january 2009; equivalent to "2009/1/1 to 2009/2/1" - -p "2009/1/1" the first day of 2009; equivalent to "2009/1/1 to + -p "2009/1/1" the first day of 2009; equivalent to "2009/1/1 to 2009/1/2" or by using the "Q" quarter-year syntax (case insensitive): - -p "2009Q1" first quarter of 2009, equivalent to "2009/1/1 to + -p "2009Q1" first quarter of 2009, equivalent to "2009/1/1 to 2009/4/1" -p "q4" fourth quarter of the current year Period expressions with a report interval - A period expression can also begin with a report interval, separated + A period expression can also begin with a report interval, separated from the start/end dates (if any) by a space or the word in: -p "weekly from 2009/1/1 to 2009/4/1" @@ -4364,10 +4455,10 @@ Time periods Weekly on a custom day: - o every Nth day of week (th, nd, rd, or st are all accepted after the + o every Nth day of week (th, nd, rd, or st are all accepted after the number) - o every WEEKDAYNAME (full or three-letter english weekday name, case + o every WEEKDAYNAME (full or three-letter english weekday name, case insensitive) Monthly on a custom day: @@ -4380,7 +4471,7 @@ Time periods o every MM/DD [of year] (month number and day of month number) - o every MONTHNAME DDth [of year] (full or three-letter english month + o every MONTHNAME DDth [of year] (full or three-letter english month name, case insensitive, and day of month number) o every DDth MONTHNAME [of year] (equivalent to the above) @@ -4393,21 +4484,21 @@ Time periods 2009/03" -p "every 2nd day of week" periods will go from Tue to Tue -p "every Tue" same - -p "every 15th day" period boundaries will be on 15th of each + -p "every 15th day" period boundaries will be on 15th of each month - -p "every 2nd Monday" period boundaries will be on second Monday + -p "every 2nd Monday" period boundaries will be on second Monday of each month - -p "every 11/05" yearly periods with boundaries on 5th of + -p "every 11/05" yearly periods with boundaries on 5th of November -p "every 5th November" same -p "every Nov 5th" same - Show historical balances at end of the 15th day of each month (N is an + Show historical balances at end of the 15th day of each month (N is an end date, exclusive as always): $ hledger balance -H -p "every 16th day" - Group postings from the start of wednesday to end of the following + Group postings from the start of wednesday to end of the following tuesday (N is both (inclusive) start date and (exclusive) end date): $ hledger register checking -p "every 3rd day of week" @@ -4418,27 +4509,27 @@ Time periods o every WEEKDAYNAME,WEEKDAYNAME,... (full or three-letter english week- day names, case insensitive) - Also, weekday and weekendday are shorthand for mon,tue,wed,thu,fri and + Also, weekday and weekendday are shorthand for mon,tue,wed,thu,fri and sat,sun. - This is mainly intended for use with --forecast, to generate periodic + This is mainly intended for use with --forecast, to generate periodic transactions on arbitrary days of the week. It may be less useful with -p, since it divides each week into subperiods of unequal length, which is unusual. (Related: #1632) Examples: - -p "every dates will be Mon, Wed, Fri; periods will be Mon- + -p "every dates will be Mon, Wed, Fri; periods will be Mon- mon,wed,fri" Tue, Wed-Thu, Fri-Sun - -p "every weekday" dates will be Mon, Tue, Wed, Thu, Fri; periods will + -p "every weekday" dates will be Mon, Tue, Wed, Thu, Fri; periods will be Mon, Tue, Wed, Thu, Fri-Sun -p "every weekend- dates will be Sat, Sun; periods will be Sat, Sun-Fri day" Depth - With the --depth NUM option (short form: -NUM), reports will show ac- - counts only to the specified depth, hiding deeper subaccounts. Use - this when you want a summary with less detail. This flag has the same + With the --depth NUM option (short form: -NUM), reports will show ac- + counts only to the specified depth, hiding deeper subaccounts. Use + this when you want a summary with less detail. This flag has the same effect as a depth: query argument: depth:2, --depth=2 or -2 are equiva- lent. @@ -4447,12 +4538,12 @@ Queries subset of your data. Most hledger commands accept optional query argu- ments to restrict their scope. The syntax is as follows: - o Zero or more space-separated query terms. These are most often ac- + o Zero or more space-separated query terms. These are most often ac- count name substrings: utilities food:groceries - o Terms with spaces or other special characters should be enclosed in + o Terms with spaces or other special characters should be enclosed in quotes: "personal care" @@ -4484,16 +4575,16 @@ Queries prefixed with not: to convert them into a negative match. acct:REGEX, REGEX - Match account names containing this (case insensitive) regular expres- + Match account names containing this (case insensitive) regular expres- sion. This is the default query type when there is no prefix, and reg- - ular expression syntax is typically not needed, so usually we just + ular expression syntax is typically not needed, so usually we just write an account name substring, like expenses or food. amt:N, amt:N, amt:>=N - Match postings with a single-commodity amount equal to, less than, or - greater than N. (Postings with multi-commodity amounts are not tested + Match postings with a single-commodity amount equal to, less than, or + greater than N. (Postings with multi-commodity amounts are not tested and will always match.) The comparison has two modes: if N is preceded - by a + or - sign (or is 0), the two signed numbers are compared. Oth- + by a + or - sign (or is 0), the two signed numbers are compared. Oth- erwise, the absolute magnitudes are compared, ignoring sign. code:REGEX @@ -4501,10 +4592,10 @@ Queries cur:REGEX Match postings or transactions including any amounts whose cur- - rency/commodity symbol is fully matched by REGEX. (For a partial - match, use .*REGEX.*). Note, to match special characters which are - regex-significant, you need to escape them with \. And for characters - which are significant to your shell you may need one more level of es- + rency/commodity symbol is fully matched by REGEX. (For a partial + match, use .*REGEX.*). Note, to match special characters which are + regex-significant, you need to escape them with \. And for characters + which are significant to your shell you may need one more level of es- caping. So eg to match the dollar sign: hledger print cur:\\$. @@ -4512,21 +4603,21 @@ Queries Match transaction descriptions. date:PERIODEXPR - Match dates (or with the --date2 flag, secondary dates) within the + Match dates (or with the --date2 flag, secondary dates) within the specified period. PERIODEXPR is a period expression with no report in- terval. Examples: date:2016, date:thismonth, date:2/1-2/15, date:2021-07-27..nextquarter. date2:PERIODEXPR - Match secondary dates within the specified period (independent of the + Match secondary dates within the specified period (independent of the --date2 flag). depth:N - Match (or display, depending on command) accounts at or above this + Match (or display, depending on command) accounts at or above this depth. expr:"TERM AND NOT (TERM OR TERM)" (eg) - Match with a boolean combination of queries (which must be enclosed in + Match with a boolean combination of queries (which must be enclosed in quotes). See Combining query terms below. note:REGEX @@ -4534,7 +4625,7 @@ Queries whole description if there's no |). payee:REGEX - Match transaction payee/payer names (the part of the description left + Match transaction payee/payer names (the part of the description left of |, or the whole description if there's no |). real:, real:0 @@ -4544,11 +4635,11 @@ Queries Match unmarked, pending, or cleared transactions respectively. type:TYPECODES - Match by account type (see Declaring accounts > Account types). TYPE- - CODES is one or more of the single-letter account type codes ALERXCV, + Match by account type (see Declaring accounts > Account types). TYPE- + CODES is one or more of the single-letter account type codes ALERXCV, case insensitive. Note type:A and type:E will also match their respec- - tive subtypes C (Cash) and V (Conversion). Certain kinds of account - alias can disrupt account types, see Rewriting accounts > Aliases and + tive subtypes C (Cash) and V (Conversion). Certain kinds of account + alias can disrupt account types, see Rewriting accounts > Aliases and account types. tag:REGEX[=REGEX] @@ -4564,11 +4655,11 @@ Queries o Transactions also acquire the tags of their postings. (inacct:ACCTNAME - A special query term used automatically in hledger-web only: tells + A special query term used automatically in hledger-web only: tells hledger-web to show the transaction register for an account.) Combining query terms - When given multiple space-separated query terms, most commands select + When given multiple space-separated query terms, most commands select things which match: o any of the description terms AND @@ -4589,13 +4680,13 @@ Queries o match all the other terms. - We also support more complex boolean queries with the 'expr:' prefix. - This allows one to combine queries using one of three operators: AND, + We also support more complex boolean queries with the 'expr:' prefix. + This allows one to combine queries using one of three operators: AND, OR, and NOT, where NOT is different syntax for 'not:'. Examples of such queries are: - o Match transactions with 'cool' in the description AND with the 'A' + o Match transactions with 'cool' in the description AND with the 'A' tag expr:"desc:cool AND tag:A" @@ -4605,22 +4696,22 @@ Queries expr:"NOT expenses:food OR tag:A" - o Match transactions NOT involving the 'expenses:food' account OR with - the 'A' tag AND involving the 'expenses:drink' account. (the AND is + o Match transactions NOT involving the 'expenses:food' account OR with + the 'A' tag AND involving the 'expenses:drink' account. (the AND is implicitly added by space-separation, following the rules above) expr:"expenses:food OR (tag:A expenses:drink)" Queries and command options - Some queries can also be expressed as command-line options: depth:2 is + Some queries can also be expressed as command-line options: depth:2 is equivalent to --depth 2, date:2023 is equivalent to -p 2023, etc. When - you mix command options and query arguments, generally the resulting + you mix command options and query arguments, generally the resulting query is their intersection. Queries and valuation - When amounts are converted to other commodities in cost or value re- - ports, cur: and amt: match the old commodity symbol and the old amount - quantity, not the new ones (except in hledger 1.22.0 where it's re- + When amounts are converted to other commodities in cost or value re- + ports, cur: and amt: match the old commodity symbol and the old amount + quantity, not the new ones (except in hledger 1.22.0 where it's re- versed, see #1625). Querying with account aliases @@ -4628,21 +4719,21 @@ Queries will match either the old or the new account name. Querying with cost or value - When amounts are converted to other commodities in cost or value re- + When amounts are converted to other commodities in cost or value re- ports, note that cur: matches the new commodity symbol, and not the old - one, and amt: matches the new quantity, and not the old one. Note: - this changed in hledger 1.22, previously it was the reverse, see the + one, and amt: matches the new quantity, and not the old one. Note: + this changed in hledger 1.22, previously it was the reverse, see the discussion at #1625. Pivoting - Normally, hledger groups and sums amounts within each account. The - --pivot FIELD option substitutes some other transaction field for ac- - count names, causing amounts to be grouped and summed by that field's - value instead. FIELD can be any of the transaction fields acct, sta- - tus, code, desc, payee, note, or a tag name. When pivoting on a tag - and a posting has multiple values of that tag, only the first value is - displayed. Values containing colon:separated:parts will be displayed - hierarchically, like account names. Multiple, colon-delimited fields + Normally, hledger groups and sums amounts within each account. The + --pivot FIELD option substitutes some other transaction field for ac- + count names, causing amounts to be grouped and summed by that field's + value instead. FIELD can be any of the transaction fields acct, sta- + tus, code, desc, payee, note, or a tag name. When pivoting on a tag + and a posting has multiple values of that tag, only the first value is + displayed. Values containing colon:separated:parts will be displayed + hierarchically, like account names. Multiple, colon-delimited fields can be pivoted simultaneously, generating a hierarchical account name. Some examples: @@ -4674,7 +4765,7 @@ Pivoting -------------------- -2 EUR - Another way (the acct: query matches against the pivoted "account + Another way (the acct: query matches against the pivoted "account name"): $ hledger balance --pivot member acct:. @@ -4692,67 +4783,67 @@ Pivoting Generating data hledger has several features for generating data, such as: - o Periodic transaction rules can generate single or repeating transac- - tions following a template. These are usually dated in the future, - eg to help with forecasting. They are activated by the --forecast + o Periodic transaction rules can generate single or repeating transac- + tions following a template. These are usually dated in the future, + eg to help with forecasting. They are activated by the --forecast option. - o The balance command's --budget option uses these same periodic rules + o The balance command's --budget option uses these same periodic rules to generate goals for the budget report. - o Auto posting rules can generate extra postings on certain matched + o Auto posting rules can generate extra postings on certain matched transactions. They are always applied to forecast transactions; with - the --auto flag they are applied to transactions recorded in the + the --auto flag they are applied to transactions recorded in the journal as well. - o The --infer-equity flag infers missing conversion equity postings - from @/@@ costs. And the inverse --infer-costs flag infers missing + o The --infer-equity flag infers missing conversion equity postings + from @/@@ costs. And the inverse --infer-costs flag infers missing @/@@ costs from conversion equity postings. Generated data of this kind is temporary, existing only at report time. - But you can see it in the output of hledger print, and you can save - that to your journal, in effect converting it from temporary generated - data to permanent recorded data. This could be useful as a data entry + But you can see it in the output of hledger print, and you can save + that to your journal, in effect converting it from temporary generated + data to permanent recorded data. This could be useful as a data entry aid. - If you are wondering what data is being generated and why, add the - --verbose-tags flag. In hledger print output you will see extra tags - like generated-transaction, generated-posting, and modified on gener- - ated/modified data. Also, even without --verbose-tags, generated data + If you are wondering what data is being generated and why, add the + --verbose-tags flag. In hledger print output you will see extra tags + like generated-transaction, generated-posting, and modified on gener- + ated/modified data. Also, even without --verbose-tags, generated data always has equivalen hidden tags (with an underscore prefix), so eg you could match generated transactions with tag:_generated-transaction. Forecasting - Forecasting, or speculative future reporting, can be useful for esti- + Forecasting, or speculative future reporting, can be useful for esti- mating future balances, or for exploring different future scenarios. The simplest and most flexible way to do it with hledger is to manually record a bunch of future-dated transactions. You could keep these in a - separate future.journal and include that with -f only when you want to + separate future.journal and include that with -f only when you want to see them. --forecast - There is another way: with the --forecast option, hledger can generate - temporary "forecast transactions" for reporting purposes, according to - periodic transaction rules defined in the journal. Each rule can gen- - erate multiple recurring transactions, so by changing one rule you can + There is another way: with the --forecast option, hledger can generate + temporary "forecast transactions" for reporting purposes, according to + periodic transaction rules defined in the journal. Each rule can gen- + erate multiple recurring transactions, so by changing one rule you can change many forecasted transactions. (These same rules can also gener- ate budget goals, described in Budgeting.) - Forecast transactions usually start after ordinary transactions end. + Forecast transactions usually start after ordinary transactions end. By default, they begin after your latest-dated ordinary transaction, or - today, whichever is later, and they end six months from today. (The + today, whichever is later, and they end six months from today. (The exact rules are a little more complicated, and are given below.) This is the "forecast period", which need not be the same as the report - period. You can override it - eg to forecast farther into the future, + period. You can override it - eg to forecast farther into the future, or to force forecast transactions to overlap your ordinary transactions - - by giving the --forecast option a period expression argument, like - --forecast=..2099 or --forecast=2023-02-15... Note that the = is re- + - by giving the --forecast option a period expression argument, like + --forecast=..2099 or --forecast=2023-02-15... Note that the = is re- quired. Inspecting forecast transactions - print is the best command for inspecting and troubleshooting forecast + print is the best command for inspecting and troubleshooting forecast transactions. Eg: ~ monthly from 2022-12-20 rent @@ -4786,7 +4877,7 @@ Forecasting expenses:rent $1000 Here there are no ordinary transactions, so the forecasted transactions - begin on the first occurence after today's date. (You won't normally + begin on the first occurence after today's date. (You won't normally use --today; it's just to make these examples reproducible.) Forecast reports @@ -4810,19 +4901,19 @@ Forecasting || $1000 $1000 $1000 $1000 $1000 Forecast tags - Forecast transactions generated by --forecast have a hidden tag, _gen- - erated-transaction. So if you ever need to match forecast transac- + Forecast transactions generated by --forecast have a hidden tag, _gen- + erated-transaction. So if you ever need to match forecast transac- tions, you could use tag:_generated-transaction (or just tag:generated) in a query. - For troubleshooting, you can add the --verbose-tags flag. Then, visi- + For troubleshooting, you can add the --verbose-tags flag. Then, visi- ble generated-transaction tags will be added also, so you can view them - with the print command. Their value indicates which periodic rule was + with the print command. Their value indicates which periodic rule was responsible. Forecast period, in detail Forecast start/end dates are chosen so as to do something useful by de- - fault in almost all situations, while also being flexible. Here are + fault in almost all situations, while also being flexible. Here are (with luck) the exact rules, to help with troubleshooting: The forecast period starts on: @@ -4854,7 +4945,7 @@ Forecasting o otherwise: 180 days (~6 months) from today. Forecast troubleshooting - When --forecast is not doing what you expect, one of these tips should + When --forecast is not doing what you expect, one of these tips should help: o Remember to use the --forecast option. @@ -4864,22 +4955,22 @@ Forecasting o Test with print --forecast. - o Check for typos or too-restrictive start/end dates in your periodic + o Check for typos or too-restrictive start/end dates in your periodic transaction rule. - o Leave at least 2 spaces between the rule's period expression and de- + o Leave at least 2 spaces between the rule's period expression and de- scription fields. - o Check for future-dated ordinary transactions suppressing forecasted + o Check for future-dated ordinary transactions suppressing forecasted transactions. o Try setting explicit report start and/or end dates with -b, -e, -p or date: - o Try adding the -E flag to encourage display of empty periods/zero + o Try adding the -E flag to encourage display of empty periods/zero transactions. - o Try setting explicit forecast start and/or end dates with --fore- + o Try setting explicit forecast start and/or end dates with --fore- cast=START..END o Consult Forecast period, in detail, above. @@ -4887,30 +4978,30 @@ Forecasting o Check inside the engine: add --debug=2 (eg). Budgeting - With the balance command's --budget report, each periodic transaction - rule generates recurring budget goals in specified accounts, and goals - and actual performance can be compared. See the balance command's doc + With the balance command's --budget report, each periodic transaction + rule generates recurring budget goals in specified accounts, and goals + and actual performance can be compared. See the balance command's doc below. - You can generate budget goals and forecast transactions at the same - time, from the same or different periodic transaction rules: hledger + You can generate budget goals and forecast transactions at the same + time, from the same or different periodic transaction rules: hledger bal -M --budget --forecast ... See also: Budgeting and Forecasting. Cost reporting In some transactions - for example a currency conversion, or a purchase - or sale of stock - one commodity is exchanged for another. In these - transactions there is a conversion rate, also called the cost (when - buying) or selling price (when selling). In hledger docs we just say + or sale of stock - one commodity is exchanged for another. In these + transactions there is a conversion rate, also called the cost (when + buying) or selling price (when selling). In hledger docs we just say "cost", for convenience; feel free to mentally translate to "conversion rate" or "selling price" if helpful. Recording costs - We'll explore several ways of recording transactions involving costs. + We'll explore several ways of recording transactions involving costs. These are also summarised at hledger Cookbook > Cost notation. - Costs can be recorded explicitly in the journal, using the @ UNITCOST + Costs can be recorded explicitly in the journal, using the @ UNITCOST or @@ TOTALCOST notation described in Journal > Costs: Variant 1 @@ -4925,11 +5016,11 @@ Cost reporting assets:dollars $-135 assets:euros 100 @@ $135 ; $135 total cost - Typically, writing the unit cost (variant 1) is preferable; it can be + Typically, writing the unit cost (variant 1) is preferable; it can be more effort, requiring more attention to decimal digits; but it reveals the per-unit cost basis, and makes stock sales easier. - Costs can also be left implicit, and hledger will infer the cost that + Costs can also be left implicit, and hledger will infer the cost that is consistent with a balanced transaction: Variant 3 @@ -4938,49 +5029,49 @@ Cost reporting assets:dollars $-135 assets:euros 100 - Here, hledger will attach a @@ 100 cost to the first amount (you can - see it with hledger print -x). This form looks convenient, but there + Here, hledger will attach a @@ 100 cost to the first amount (you can + see it with hledger print -x). This form looks convenient, but there are downsides: - o It sacrifices some error checking. For example, if you accidentally + o It sacrifices some error checking. For example, if you accidentally wrote 10 instead of 100, hledger would not be able to detect the mis- take. - o It is sensitive to the order of postings - if they were reversed, a + o It is sensitive to the order of postings - if they were reversed, a different entry would be inferred and reports would be different. o The per-unit cost basis is not easy to read. - So generally this kind of entry is not recommended. You can make sure + So generally this kind of entry is not recommended. You can make sure you have none of these by using -s (strict mode), or by running hledger check balanced. Reporting at cost - Now when you add the -B/--cost flag to reports ("B" is from Ledger's - -B/--basis/--cost flag), any amounts which have been annotated with - costs will be converted to their cost's commodity (in the report out- + Now when you add the -B/--cost flag to reports ("B" is from Ledger's + -B/--basis/--cost flag), any amounts which have been annotated with + costs will be converted to their cost's commodity (in the report out- put). Ie they will be displayed "at cost" or "at sale price". Some things to note: - o Costs are attached to specific posting amounts in specific transac- - tions, and once recorded they do not change. This contrasts with + o Costs are attached to specific posting amounts in specific transac- + tions, and once recorded they do not change. This contrasts with market prices, which are ambient and fluctuating. - o Conversion to cost is performed before conversion to market value + o Conversion to cost is performed before conversion to market value (described below). Equity conversion postings - There is a problem with the entries above - they are not conventional - Double Entry Bookkeeping (DEB) notation, and because of the "magical" - transformation of one commodity into another, they cause an imbalance + There is a problem with the entries above - they are not conventional + Double Entry Bookkeeping (DEB) notation, and because of the "magical" + transformation of one commodity into another, they cause an imbalance in the Accounting Equation. This shows up as a non-zero grand total in balance reports like hledger bse. - For most hledger users, this doesn't matter in practice and can safely + For most hledger users, this doesn't matter in practice and can safely be ignored ! But if you'd like to learn more, keep reading. - Conventional DEB uses an extra pair of equity postings to balance the + Conventional DEB uses an extra pair of equity postings to balance the transaction. Of course you can do this in hledger as well: Variant 4 @@ -4991,10 +5082,10 @@ Cost reporting equity:conversion $135 equity:conversion -100 - Now the transaction is perfectly balanced according to standard DEB, + Now the transaction is perfectly balanced according to standard DEB, and hledger bse's total will not be disrupted. - And, hledger can still infer the cost for cost reporting, but it's not + And, hledger can still infer the cost for cost reporting, but it's not done by default - you must add the --infer-costs flag like so: $ hledger print --infer-costs @@ -5016,14 +5107,14 @@ Cost reporting o Instead of -B you must remember to type -B --infer-costs. - o --infer-costs works only where hledger can identify the two eq- - uity:conversion postings and match them up with the two non-equity - postings. So writing the journal entry in a particular format be- + o --infer-costs works only where hledger can identify the two eq- + uity:conversion postings and match them up with the two non-equity + postings. So writing the journal entry in a particular format be- comes more important. More on this below. Inferring equity conversion postings Can we go in the other direction ? Yes, if you have transactions writ- - ten with the @/@@ cost notation, hledger can infer the missing equity + ten with the @/@@ cost notation, hledger can infer the missing equity postings, if you add the --infer-equity flag. Eg: 2022-01-01 @@ -5037,15 +5128,15 @@ Cost reporting equity:conversion:$-: -100 equity:conversion:$-:$ $135.00 - The equity account names will be "equity:conversion:A-B:A" and "eq- - uity:conversion:A-B:B" where A is the alphabetically first commodity + The equity account names will be "equity:conversion:A-B:A" and "eq- + uity:conversion:A-B:B" where A is the alphabetically first commodity symbol. You can customise the "equity:conversion" part by declaring an account with the V/Conversion account type. Combining costs and equity conversion postings Finally, you can use both the @/@@ cost notation and equity postings at - the same time. This in theory gives the best of all worlds - preserv- - ing the accounting equation, revealing the per-unit cost basis, and + the same time. This in theory gives the best of all worlds - preserv- + ing the accounting equation, revealing the per-unit cost basis, and providing more flexibility in how you write the entry: Variant 5 @@ -5056,7 +5147,7 @@ Cost reporting equity:conversion -100 assets:euros 100 @ $1.35 - All the other variants above can (usually) be rewritten to this final + All the other variants above can (usually) be rewritten to this final form with: $ hledger print -x --infer-costs --infer-equity @@ -5065,8 +5156,8 @@ Cost reporting o This was added in hledger-1.29 and is still somewhat experimental. - o The precise format of the journal entry becomes more important. If - hledger can't detect and match up the cost and equity postings, it + o The precise format of the journal entry becomes more important. If + hledger can't detect and match up the cost and equity postings, it will give a transaction balancing error. o The add command does not yet accept this kind of entry (#2056). @@ -5074,34 +5165,34 @@ Cost reporting o This is the most verbose form. Requirements for detecting equity conversion postings - --infer-costs has certain requirements (unlike --infer-equity, which + --infer-costs has certain requirements (unlike --infer-equity, which always works). It will infer costs only in transactions with: - o Two non-equity postings, in different commodities. Their order is + o Two non-equity postings, in different commodities. Their order is significant: the cost will be added to the first of them. - o Two postings to equity conversion accounts, next to one another, + o Two postings to equity conversion accounts, next to one another, which balance the two non-equity postings. This balancing is checked - to the same precision (number of decimal places) used in the conver- + to the same precision (number of decimal places) used in the conver- sion posting's amount. Equity conversion accounts are: o any accounts declared with account type V/Conversion, or their sub- accounts - o otherwise, accounts named equity:conversion, equity:trade, or eq- + o otherwise, accounts named equity:conversion, equity:trade, or eq- uity:trading, or their subaccounts. - And multiple such four-posting groups can coexist within a single - transaction. When --infer-costs fails, it does not infer a cost in - that transaction, and does not raise an error (ie, it infers costs + And multiple such four-posting groups can coexist within a single + transaction. When --infer-costs fails, it does not infer a cost in + that transaction, and does not raise an error (ie, it infers costs where it can). - Reading variant 5 journal entries, combining cost notation and equity - postings, has all the same requirements. When reading such an entry + Reading variant 5 journal entries, combining cost notation and equity + postings, has all the same requirements. When reading such an entry fails, hledger raises an "unbalanced transaction" error. Infer cost and equity by default ? - Should --infer-costs and --infer-equity be enabled by default ? Try + Should --infer-costs and --infer-equity be enabled by default ? Try using them always, eg with a shell alias: alias h="hledger --infer-equity --infer-costs" @@ -5109,93 +5200,101 @@ Cost reporting and let us know what problems you find. Value reporting - Instead of reporting amounts in their original commodity, hledger can + Instead of reporting amounts in their original commodity, hledger can convert them to cost/sale amount (using the conversion rate recorded in - the transaction), and/or to market value (using some market price on a - certain date). This is controlled by the --value=TYPE[,COMMODITY] op- - tion, which will be described below. We also provide the simpler -V + the transaction), and/or to market value (using some market price on a + certain date). This is controlled by the --value=TYPE[,COMMODITY] op- + tion, which will be described below. We also provide the simpler -V and -X COMMODITY options, and often one of these is all you need: -V: Value - The -V/--market flag converts amounts to market value in their default + The -V/--market flag converts amounts to market value in their default valuation commodity, using the market prices in effect on the valuation date(s), if any. More on these in a minute. -X: Value in specified commodity The -X/--exchange=COMM option is like -V, except you tell it which cur- - rency you want to convert to, and it tries to convert everything to + rency you want to convert to, and it tries to convert everything to that. Valuation date - Since market prices can change from day to day, market value reports - have a valuation date (or more than one), which determines which market - prices will be used. + Market prices can change from day to day. hledger will use the prices + on a particular valuation date (or on more than one date). By default + hledger uses "end" dates for valuation. More specifically: - For single period reports, if an explicit report end date is specified, - that will be used as the valuation date; otherwise the valuation date - is the journal's end date. + o For single period reports (including normal print and register re- + ports): - For multiperiod reports, each column/period is valued on the last day - of the period, by default. + o If an explicit report end date is specified, that is used + + o Otherwise the latest transaction date or P directive date is used + (even if it's in the future) + + o For multiperiod reports, each period is valued on its last day. + + This can be customised with the --value option described below, which + can select either "then", "end", "now", or "custom" dates. (Note, this + has a bug in hledger-ui <=1.31: turning on valuation with the V key al- + ways resets it to "end".) Finding market price - To convert a commodity A to its market value in another commodity B, - hledger looks for a suitable market price (exchange rate) as follows, - in this order of preference : + To convert a commodity A to its market value in another commodity B, + hledger looks for a suitable market price (exchange rate) as follows, + in this order of preference: - 1. A declared market price or inferred market price: A's latest market + 1. A declared market price or inferred market price: A's latest market price in B on or before the valuation date as declared by a P direc- tive, or (with the --infer-market-prices flag) inferred from costs. 2. A reverse market price: the inverse of a declared or inferred market price from B to A. - 3. A forward chain of market prices: a synthetic price formed by com- + 3. A forward chain of market prices: a synthetic price formed by com- bining the shortest chain of "forward" (only 1 above) market prices, leading from A to B. - 4. Any chain of market prices: a chain of any market prices, including - both forward and reverse prices (1 and 2 above), leading from A to + 4. Any chain of market prices: a chain of any market prices, including + both forward and reverse prices (1 and 2 above), leading from A to B. - There is a limit to the length of these price chains; if hledger - reaches that length without finding a complete chain or exhausting all - possibilities, it will give up (with a "gave up" message visible in + There is a limit to the length of these price chains; if hledger + reaches that length without finding a complete chain or exhausting all + possibilities, it will give up (with a "gave up" message visible in --debug=2 output). That limit is currently 1000. - Amounts for which no suitable market price can be found, are not con- + Amounts for which no suitable market price can be found, are not con- verted. --infer-market-prices: market prices from transactions Normally, market value in hledger is fully controlled by, and requires, P directives in your journal. Since adding and updating those can be a - chore, and since transactions usually take place at close to market - value, why not use the recorded costs as additional market prices (as - Ledger does) ? Adding the --infer-market-prices flag to -V, -X or + chore, and since transactions usually take place at close to market + value, why not use the recorded costs as additional market prices (as + Ledger does) ? Adding the --infer-market-prices flag to -V, -X or --value enables this. - So for example, hledger bs -V --infer-market-prices will get market - prices both from P directives and from transactions. If both occur on + So for example, hledger bs -V --infer-market-prices will get market + prices both from P directives and from transactions. If both occur on the same day, the P directive takes precedence. There is a downside: value reports can sometimes be affected in confus- - ing/undesired ways by your journal entries. If this happens to you, - read all of this Value reporting section carefully, and try adding + ing/undesired ways by your journal entries. If this happens to you, + read all of this Value reporting section carefully, and try adding --debug or --debug=2 to troubleshoot. --infer-market-prices can infer market prices from: o multicommodity transactions with explicit prices (@/@@) - o multicommodity transactions with implicit prices (no @, two commodi- - ties, unbalanced). (With these, the order of postings matters. + o multicommodity transactions with implicit prices (no @, two commodi- + ties, unbalanced). (With these, the order of postings matters. hledger print -x can be useful for troubleshooting.) o multicommodity transactions with equity postings, if cost is inferred with --infer-costs. - There is a limitation (bug) currently: when a valuation commodity is - not specified, prices inferred with --infer-market-prices do not help + There is a limitation (bug) currently: when a valuation commodity is + not specified, prices inferred with --infer-market-prices do not help select a default valuation commodity, as P prices would. So conversion might not happen because no valuation commodity was detected (--debug=2 will show this). To be safe, specify the valuation commmodity, eg: @@ -5205,8 +5304,8 @@ Value reporting o --value=then,EUR --infer-market-prices, not --value=then --infer-mar- ket-prices - Signed costs and market prices can be confusing. For reference, here - is the current behaviour, since hledger 1.25. (If you think it should + Signed costs and market prices can be confusing. For reference, here + is the current behaviour, since hledger 1.25. (If you think it should work differently, see #1870.) 2022-01-01 Positive Unit prices @@ -5236,7 +5335,7 @@ Value reporting b B -1 @@ A -1 All of the transactions above are considered balanced (and on each day, - the two transactions are considered equivalent). Here are the market + the two transactions are considered equivalent). Here are the market prices inferred for B: $ hledger -f- --infer-market-prices prices @@ -5249,34 +5348,34 @@ Value reporting Valuation commodity When you specify a valuation commodity (-X COMM or --value TYPE,COMM): - hledger will convert all amounts to COMM, wherever it can find a suit- + hledger will convert all amounts to COMM, wherever it can find a suit- able market price (including by reversing or chaining prices). - When you leave the valuation commodity unspecified (-V or --value + When you leave the valuation commodity unspecified (-V or --value TYPE): - For each commodity A, hledger picks a default valuation commodity as + For each commodity A, hledger picks a default valuation commodity as follows, in this order of preference: 1. The price commodity from the latest P-declared market price for A on or before valuation date. 2. The price commodity from the latest P-declared market price for A on - any date. (Allows conversion to proceed when there are inferred + any date. (Allows conversion to proceed when there are inferred prices before the valuation date.) - 3. If there are no P directives at all (any commodity or date) and the - --infer-market-prices flag is used: the price commodity from the + 3. If there are no P directives at all (any commodity or date) and the + --infer-market-prices flag is used: the price commodity from the latest transaction-inferred price for A on or before valuation date. This means: - o If you have P directives, they determine which commodities -V will + o If you have P directives, they determine which commodities -V will convert, and to what. - o If you have no P directives, and use the --infer-market-prices flag, + o If you have no P directives, and use the --infer-market-prices flag, costs determine it. - Amounts for which no valuation commodity can be found are not con- + Amounts for which no valuation commodity can be found are not con- verted. Simple valuation examples @@ -5303,7 +5402,7 @@ Value reporting $ hledger -f t.j bal -N euros -V -e 2016/11/4 $110.00 assets:euros - What are they worth after 2016/12/21 ? (no report end date specified, + What are they worth after 2016/12/21 ? (no report end date specified, defaults to today) $ hledger -f t.j bal -N euros -V @@ -5323,31 +5422,31 @@ Value reporting The TYPE part selects cost or value and valuation date: --value=then - Convert amounts to their value in the default valuation commod- + Convert amounts to their value in the default valuation commod- ity, using market prices on each posting's date. --value=end - Convert amounts to their value in the default valuation commod- - ity, using market prices on the last day of the report period - (or if unspecified, the journal's end date); or in multiperiod + Convert amounts to their value in the default valuation commod- + ity, using market prices on the last day of the report period + (or if unspecified, the journal's end date); or in multiperiod reports, market prices on the last day of each subperiod. --value=now - Convert amounts to their value in the default valuation commod- - ity using current market prices (as of when report is gener- + Convert amounts to their value in the default valuation commod- + ity using current market prices (as of when report is gener- ated). --value=YYYY-MM-DD - Convert amounts to their value in the default valuation commod- + Convert amounts to their value in the default valuation commod- ity using market prices on this date. To select a different valuation commodity, add the optional ,COMM part: - a comma, then the target commodity's symbol. Eg: --value=now,EUR. + a comma, then the target commodity's symbol. Eg: --value=now,EUR. hledger will do its best to convert amounts to this commodity, deducing market prices as described above. More valuation examples - Here are some examples showing the effect of --value, as seen with + Here are some examples showing the effect of --value, as seen with print: P 2000-01-01 A 1 B @@ -5385,7 +5484,7 @@ Value reporting 2000-02-01 (a) 2 B - With no report period specified, that shows the value as of the last + With no report period specified, that shows the value as of the last day of the journal (2000-03-01): $ hledger -f- print --value=end @@ -5422,40 +5521,8 @@ Value reporting 2000-03-01 (a) 1 B - You may need to explicitly set a commodity's display style, when re- - verse prices are used. Eg this output might be surprising: - - P 2000-01-01 A 2B - - 2000-01-01 - a 1B - b - - $ hledger print -x -X A - 2000-01-01 - a 0 - b 0 - - Explanation: because there's no amount or commodity directive specify- - ing a display style for A, 0.5A gets the default style, which shows no - decimal digits. Because the displayed amount looks like zero, the com- - modity symbol and minus sign are not displayed either. Adding a com- - modity directive sets a more useful display style for A: - - P 2000-01-01 A 2B - commodity 0.00A - - 2000-01-01 - a 1B - b - - $ hledger print -X A - 2000-01-01 - a 0.50A - b -0.50A - Interaction of valuation and queries - When matching postings based on queries in the presence of valuation, + When matching postings based on queries in the presence of valuation, the following happens. 1. The query is separated into two parts: @@ -5469,15 +5536,15 @@ Value reporting 3. Valuation is applied to the postings. - 4. The postings are matched to the other parts of the query based on + 4. The postings are matched to the other parts of the query based on post-valued amounts. See: 1625 Effect of valuation on reports - Here is a reference for how valuation is supposed to affect each part - of hledger's reports (and a glossary). (It's wide, you'll have to - scroll sideways.) It may be useful when troubleshooting. If you find + Here is a reference for how valuation is supposed to affect each part + of hledger's reports (and a glossary). (It's wide, you'll have to + scroll sideways.) It may be useful when troubleshooting. If you find problems, please report them, ideally with a reproducible example. Re- lated: #329, #1083. @@ -5485,8 +5552,8 @@ Value reporting type --value=now -------------------------------------------------------------------------------------------- print - posting cost value at re- value at posting value at re- value at - amounts port end or date port or DATE/today + posting cost value at re- value at posting value at re- value at + amounts port end or date port or DATE/today today journal end balance unchanged unchanged unchanged unchanged unchanged asser- @@ -5502,7 +5569,7 @@ Value reporting (-H) with port or posting was made port or report journal journal interval start start - posting cost value at re- value at posting value at re- value at + posting cost value at re- value at posting value at re- value at amounts port or date port or DATE/today journal end journal end summary summarised value at pe- sum of postings value at pe- value at @@ -5518,8 +5585,8 @@ Value reporting balance (bs, bse, cf, is) - balance sums of value at re- value at posting value at re- value at - changes costs port end or date port or DATE/today of + balance sums of value at re- value at posting value at re- value at + changes costs port end or date port or DATE/today of today of journal end sums of post- sums of of sums of ings postings postings @@ -5527,7 +5594,7 @@ Value reporting amounts changes changes changes ances changes (--bud- get) - grand to- sum of dis- sum of dis- sum of displayed sum of dis- sum of dis- + grand to- sum of dis- sum of dis- sum of displayed sum of dis- sum of dis- tal played val- played val- valued played val- played values ues ues ues @@ -5553,7 +5620,7 @@ Value reporting end bal- sums of same as sums of values of period end value at ances costs of --value=end postings from be- balances, DATE/today of (bal -H, postings fore period start valued at sums of post- - is --H, from before to period end at period ends ings + is --H, from before to period end at period ends ings bs, cf) report start respective post- to period ing dates end @@ -5562,10 +5629,10 @@ Value reporting (--bud- balances balances ances balances get) row to- sums, aver- sums, aver- sums, averages of sums, aver- sums, aver- - tals, row ages of dis- ages of dis- displayed values ages of dis- ages of dis- + tals, row ages of dis- ages of dis- displayed values ages of dis- ages of dis- averages played val- played val- played val- played values (-T, -A) ues ues ues - column sums of dis- sums of dis- sums of displayed sums of dis- sums of dis- + column sums of dis- sums of dis- sums of displayed sums of dis- sums of dis- totals played val- played val- values played val- played values ues ues ues grand to- sum, average sum, average sum, average of sum, average sum, average @@ -5581,29 +5648,29 @@ Value reporting cost calculated using price(s) recorded in the transaction(s). - value market value using available market price declarations, or the + value market value using available market price declarations, or the unchanged amount if no conversion rate can be found. report start - the first day of the report period specified with -b or -p or + the first day of the report period specified with -b or -p or date:, otherwise today. report or journal start - the first day of the report period specified with -b or -p or - date:, otherwise the earliest transaction date in the journal, + the first day of the report period specified with -b or -p or + date:, otherwise the earliest transaction date in the journal, otherwise today. report end - the last day of the report period specified with -e or -p or + the last day of the report period specified with -e or -p or date:, otherwise today. report or journal end - the last day of the report period specified with -e or -p or - date:, otherwise the latest transaction date in the journal, + the last day of the report period specified with -e or -p or + date:, otherwise the latest transaction date in the journal, otherwise today. report interval - a flag (-D/-W/-M/-Q/-Y) or period expression that activates the + a flag (-D/-W/-M/-Q/-Y) or period expression that activates the report's multi-period mode (whether showing one or many subperi- ods). @@ -5645,7 +5712,7 @@ PART 4: COMMANDS o print - show transactions or export journal data - o register (reg) - show postings in one or more accounts & running to- + o register (reg) - show postings in one or more accounts & running to- tal o roi - show return on investments @@ -5682,7 +5749,7 @@ PART 4: COMMANDS ADD-ONS And here are some typical add-on commands. Some of these are installed - by the hledger-install script. If installed, they will appear in + by the hledger-install script. If installed, they will appear in hledger's commands list: o ui - run hledger's terminal UI @@ -5695,7 +5762,7 @@ PART 4: COMMANDS o stockquotes - download market prices from AlphaVantage - o Scripts and add-ons - check-fancyassertions, edit, fifo, git, move, + o Scripts and add-ons - check-fancyassertions, edit, fifo, git, move, pijul, plot, and more.. Next, each command is described in detail, in alphabetical order. @@ -5703,38 +5770,38 @@ PART 4: COMMANDS accounts Show account names. - This command lists account names. By default it shows all known ac- - counts, either used in transactions or declared with account direc- + This command lists account names. By default it shows all known ac- + counts, either used in transactions or declared with account direc- tives. With query arguments, only matched account names and account names ref- erenced by matched postings are shown. - Or it can show just the used accounts (--used/-u), the declared ac- - counts (--declared/-d), the accounts declared but not used (--unused), + Or it can show just the used accounts (--used/-u), the declared ac- + counts (--declared/-d), the accounts declared but not used (--unused), the accounts used but not declared (--undeclared), or the first account matched by an account name pattern, if any (--find). - It shows a flat list by default. With --tree, it uses indentation to - show the account hierarchy. In flat mode you can add --drop N to omit - the first few account name components. Account names can be depth- + It shows a flat list by default. With --tree, it uses indentation to + show the account hierarchy. In flat mode you can add --drop N to omit + the first few account name components. Account names can be depth- clipped with depth:N or --depth N or -N. - With --types, it also shows each account's type, if it's known. (See + With --types, it also shows each account's type, if it's known. (See Declaring accounts > Account types.) - With --positions, it also shows the file and line number of each ac- - count's declaration, if any, and the account's overall declaration or- + With --positions, it also shows the file and line number of each ac- + count's declaration, if any, and the account's overall declaration or- der; these may be useful when troubleshooting account display order. - With --directives, it adds the account keyword, showing valid account + With --directives, it adds the account keyword, showing valid account directives which can be pasted into a journal file. This is useful to- - gether with --undeclared when updating your account declarations to + gether with --undeclared when updating your account declarations to satisfy hledger check accounts. - The --find flag can be used to look up a single account name, in the - same way that the aregister command does. It returns the alphanumeri- - cally-first matched account name, or if none can be found, it fails + The --find flag can be used to look up a single account name, in the + same way that the aregister command does. It returns the alphanumeri- + cally-first matched account name, or if none can be found, it fails with a non-zero exit code. Examples: @@ -5755,8 +5822,8 @@ PART 4: COMMANDS activity Show an ascii barchart of posting counts per interval. - The activity command displays an ascii histogram showing transaction - counts by day, week, month or other reporting interval (by day is the + The activity command displays an ascii histogram showing transaction + counts by day, week, month or other reporting interval (by day is the default). With query arguments, it counts only matched transactions. Examples: @@ -5768,36 +5835,36 @@ PART 4: COMMANDS 2008-10-01 ** add - Prompt for transactions and add them to the journal. Any arguments + Prompt for transactions and add them to the journal. Any arguments will be used as default inputs for the first N prompts. - Many hledger users edit their journals directly with a text editor, or - generate them from CSV. For more interactive data entry, there is the - add command, which prompts interactively on the console for new trans- - actions, and appends them to the main journal file (which should be in - journal format). Existing transactions are not changed. This is one - of the few hledger commands that writes to the journal file (see also + Many hledger users edit their journals directly with a text editor, or + generate them from CSV. For more interactive data entry, there is the + add command, which prompts interactively on the console for new trans- + actions, and appends them to the main journal file (which should be in + journal format). Existing transactions are not changed. This is one + of the few hledger commands that writes to the journal file (see also import). To use it, just run hledger add and follow the prompts. You can add as - many transactions as you like; when you are finished, enter . or press + many transactions as you like; when you are finished, enter . or press control-d or control-c to exit. Features: - o add tries to provide useful defaults, using the most similar (by de- - scription) recent transaction (filtered by the query, if any) as a + o add tries to provide useful defaults, using the most similar (by de- + scription) recent transaction (filtered by the query, if any) as a template. o You can also set the initial defaults with command line arguments. o Readline-style edit keys can be used during data entry. - o The tab key will auto-complete whenever possible - accounts, pay- - ees/descriptions, dates (yesterday, today, tomorrow). If the input + o The tab key will auto-complete whenever possible - accounts, pay- + ees/descriptions, dates (yesterday, today, tomorrow). If the input area is empty, it will insert the default value. - o If the journal defines a default commodity, it will be added to any + o If the journal defines a default commodity, it will be added to any bare numbers entered. o A parenthesised transaction code may be entered following a date. @@ -5806,7 +5873,7 @@ PART 4: COMMANDS o If you make a mistake, enter < at any prompt to go one step backward. - o Input prompts are displayed in a different colour when the terminal + o Input prompts are displayed in a different colour when the terminal supports it. Example (see https://hledger.org/add.html for a detailed tutorial): @@ -5836,102 +5903,106 @@ PART 4: COMMANDS Starting the next transaction (. or ctrl-D/ctrl-C to quit) Date [2015/05/22]: $ - On Microsoft Windows, the add command makes sure that no part of the + On Microsoft Windows, the add command makes sure that no part of the file path ends with a period, as that would cause problems (#1056). aregister (areg) - Show the transactions and running historical balance of a single ac- + Show the transactions and running historical balance of a single ac- count, with each transaction displayed as one line. aregister shows the overall transactions affecting a particular account - (and any subaccounts). Each report line represents one transaction in + (and any subaccounts). Each report line represents one transaction in this account. Transactions before the report start date are always in- cluded in the running balance (--historical mode is always on). - This is a more "real world", bank-like view than the register command - (which shows individual postings, possibly from multiple accounts, not + This is a more "real world", bank-like view than the register command + (which shows individual postings, possibly from multiple accounts, not necessarily in historical mode). As a quick rule of thumb: - use areg- ister for reviewing and reconciling real-world asset/liability accounts - use register for reviewing detailed revenues/expenses. - aregister requires one argument: the account to report on. You can - write either the full account name, or a case-insensitive regular ex- + aregister requires one argument: the account to report on. You can + write either the full account name, or a case-insensitive regular ex- pression which will select the alphabetically first matched account. When there are multiple matches, the alphabetically-first choice can be - surprising; eg if you have assets:per:checking 1 and assets:biz:check- - ing 2 accounts, hledger areg checking would select assets:biz:checking - 2. It's just a convenience to save typing, so if in doubt, write the + surprising; eg if you have assets:per:checking 1 and assets:biz:check- + ing 2 accounts, hledger areg checking would select assets:biz:checking + 2. It's just a convenience to save typing, so if in doubt, write the full account name, or a distinctive substring that matches uniquely. - Transactions involving subaccounts of this account will also be shown. - aregister ignores depth limits, so its final total will always match a + Transactions involving subaccounts of this account will also be shown. + aregister ignores depth limits, so its final total will always match a balance report with similar arguments. - Any additional arguments form a query which will filter the transac- + Any additional arguments form a query which will filter the transac- tions shown. Note some queries will disturb the running balance, caus- ing it to be different from the account's real-world running balance. - An example: this shows the transactions and historical running balance + An example: this shows the transactions and historical running balance during july, in the first account whose name contains "checking": $ hledger areg checking date:jul Each aregister line item shows: - o the transaction's date (or the relevant posting's date if different, + o the transaction's date (or the relevant posting's date if different, see below) - o the names of all the other account(s) involved in this transaction + o the names of all the other account(s) involved in this transaction (probably abbreviated) o the total change to this account's balance from this transaction o the account's historical running balance after this transaction. - Transactions making a net change of zero are not shown by default; add + Transactions making a net change of zero are not shown by default; add the -E/--empty flag to show them. - For performance reasons, column widths are chosen based on the first - 1000 lines; this means unusually wide values in later lines can cause - visual discontinuities as column widths are adjusted. If you want to - ensure perfect alignment, at the cost of more time and memory, use the + For performance reasons, column widths are chosen based on the first + 1000 lines; this means unusually wide values in later lines can cause + visual discontinuities as column widths are adjusted. If you want to + ensure perfect alignment, at the cost of more time and memory, use the --align-all flag. This command also supports the output destination and output format op- - tions. The output formats supported are txt, csv, and json. + tions. The output formats supported are txt, csv, tsv, and json. - aregister and custom posting dates - Transactions whose date is outside the report period can still be - shown, if they have a posting to this account dated inside the report - period. (And in this case it's the posting date that is shown.) This - ensures that aregister can show an accurate historical running balance, - matching the one shown by register -H with the same arguments. + aregister and posting dates + aregister always shows one line (and date and amount) per transaction. + But sometimes transactions have postings with different dates. Also, + not all of a transaction's postings may be within the report period. + To resolve this, aregister shows the earliest of the transaction's date + and posting dates that is in-period, and the sum of the in-period post- + ings. In other words it will show a combined line item with just the + earliest date, and the running balance will (temporarily, until the + transaction's last posting) be inaccurate. Use register -H if you need + to see the individual postings. - To filter strictly by transaction date instead, add the --txn-dates - flag. If you use this flag and some of your postings have custom - dates, it's probably best to assume the running balance is wrong. + There is also a --txn-dates flag, which filters strictly by transaction + date, ignoring posting dates. This too can cause an inaccurate running + balance. balance (bal) Show accounts and their balances. - balance is one of hledger's oldest and most versatile commands, for - listing account balances, balance changes, values, value changes and + balance is one of hledger's oldest and most versatile commands, for + listing account balances, balance changes, values, value changes and more, during one time period or many. Generally it shows a table, with rows representing accounts, and columns representing periods. - Note there are some higher-level variants of the balance command with - convenient defaults, which can be simpler to use: balancesheet, bal- + Note there are some higher-level variants of the balance command with + convenient defaults, which can be simpler to use: balancesheet, bal- ancesheetequity, cashflow and incomestatement. When you need more con- trol, then use balance. balance features - Here's a quick overview of the balance command's features, followed by - more detailed descriptions and examples. Many of these work with the + Here's a quick overview of the balance command's features, followed by + more detailed descriptions and examples. Many of these work with the higher-level commands as well. balance can show.. @@ -5984,7 +6055,7 @@ PART 4: COMMANDS ..with.. - o totals (-T), averages (-A), percentages (-%), inverted sign (--in- + o totals (-T), averages (-A), percentages (-%), inverted sign (--in- vert) o rows and columns swapped (--transpose) @@ -5996,24 +6067,24 @@ PART 4: COMMANDS o commodities displayed on the same line or multiple lines (--layout) This command supports the output destination and output format options, - with output formats txt, csv, json, and (multi-period reports only:) - html. In txt output in a colour-supporting terminal, negative amounts - are shown in red. + with output formats txt, csv, tsv, json, and (multi-period reports + only:) html. In txt output in a colour-supporting terminal, negative + amounts are shown in red. - The --related/-r flag shows the balance of the other postings in the + The --related/-r flag shows the balance of the other postings in the transactions of the postings which would normally be shown. Simple balance report - With no arguments, balance shows a list of all accounts and their - change of balance - ie, the sum of posting amounts, both inflows and - outflows - during the entire period of the journal. ("Simple" here - means just one column of numbers, covering a single period. You can + With no arguments, balance shows a list of all accounts and their + change of balance - ie, the sum of posting amounts, both inflows and + outflows - during the entire period of the journal. ("Simple" here + means just one column of numbers, covering a single period. You can also have multi-period reports, described later.) - For real-world accounts, these numbers will normally be their end bal- + For real-world accounts, these numbers will normally be their end bal- ance at the end of the journal period; more on this below. - Accounts are sorted by declaration order if any, and then alphabeti- + Accounts are sorted by declaration order if any, and then alphabeti- cally by account name. For instance (using examples/sample.journal): $ hledger -f examples/sample.journal bal @@ -6028,7 +6099,7 @@ PART 4: COMMANDS 0 Accounts with a zero balance (and no non-zero subaccounts, in tree mode - - see below) are hidden by default. Use -E/--empty to show them (re- + - see below) are hidden by default. Use -E/--empty to show them (re- vealing assets:bank:checking here): $ hledger -f examples/sample.journal bal -E @@ -6043,12 +6114,12 @@ PART 4: COMMANDS -------------------- 0 - The total of the amounts displayed is shown as the last line, unless + The total of the amounts displayed is shown as the last line, unless -N/--no-total is used. Balance report line format For single-period balance reports displayed in the terminal (only), you - can use --format FMT to customise the format and content of each line. + can use --format FMT to customise the format and content of each line. Eg: $ hledger -f examples/sample.journal balance --format "%20(account) %12(total)" @@ -6065,7 +6136,7 @@ PART 4: COMMANDS --------------------------------- 0 - The FMT format string specifies the formatting applied to each ac- + The FMT format string specifies the formatting applied to each ac- count/balance pair. It may contain any suitable text, with data fields interpolated like so: @@ -6077,14 +6148,14 @@ PART 4: COMMANDS o FIELDNAME must be enclosed in parentheses, and can be one of: - o depth_spacer - a number of spaces equal to the account's depth, or + o depth_spacer - a number of spaces equal to the account's depth, or if MIN is specified, MIN * depth spaces. o account - the account's name o total - the account's balance/posted total, right justified - Also, FMT can begin with an optional prefix to control how multi-com- + Also, FMT can begin with an optional prefix to control how multi-com- modity amounts are rendered: o %_ - render on multiple lines, bottom-aligned (the default) @@ -6101,18 +6172,18 @@ PART 4: COMMANDS o %(total) - the account's total - o %-20.20(account) - the account's name, left justified, padded to 20 + o %-20.20(account) - the account's name, left justified, padded to 20 characters and clipped at 20 characters - o %,%-50(account) %25(total) - account name padded to 50 characters, - total padded to 20 characters, with multiple commodities rendered on + o %,%-50(account) %25(total) - account name padded to 50 characters, + total padded to 20 characters, with multiple commodities rendered on one line - o %20(total) %2(depth_spacer)%-(account) - the default format for the + o %20(total) %2(depth_spacer)%-(account) - the default format for the single-column balance report Filtered balance report - You can show fewer accounts, a different time period, totals from + You can show fewer accounts, a different time period, totals from cleared transactions only, etc. by using query arguments or options to limit the postings being matched. Eg: @@ -6122,10 +6193,10 @@ PART 4: COMMANDS $-2 List or tree mode - By default, or with -l/--flat, accounts are shown as a flat list with + By default, or with -l/--flat, accounts are shown as a flat list with their full names visible, as in the examples above. - With -t/--tree, the account hierarchy is shown, with subaccounts' + With -t/--tree, the account hierarchy is shown, with subaccounts' "leaf" names indented below their parent: $ hledger -f examples/sample.journal balance @@ -6145,26 +6216,26 @@ PART 4: COMMANDS Notes: o "Boring" accounts are combined with their subaccount for more compact - output, unless --no-elide is used. Boring accounts have no balance - of their own and just one subaccount (eg assets:bank and liabilities + output, unless --no-elide is used. Boring accounts have no balance + of their own and just one subaccount (eg assets:bank and liabilities above). - o All balances shown are "inclusive", ie including the balances from - all subaccounts. Note this means some repetition in the output, + o All balances shown are "inclusive", ie including the balances from + all subaccounts. Note this means some repetition in the output, which requires explanation when sharing reports with non-plaintextac- - counting-users. A tree mode report's final total is the sum of the + counting-users. A tree mode report's final total is the sum of the top-level balances shown, not of all the balances shown. - o Each group of sibling accounts (ie, under a common parent) is sorted + o Each group of sibling accounts (ie, under a common parent) is sorted separately. Depth limiting - With a depth:NUM query, or --depth NUM option, or just -NUM (eg: -3) - balance reports will show accounts only to the specified depth, hiding - the deeper subaccounts. This can be useful for getting an overview + With a depth:NUM query, or --depth NUM option, or just -NUM (eg: -3) + balance reports will show accounts only to the specified depth, hiding + the deeper subaccounts. This can be useful for getting an overview without too much detail. - Account balances at the depth limit always include the balances from + Account balances at the depth limit always include the balances from any deeper subaccounts (even in list mode). Eg, limiting to depth 1: $ hledger -f examples/sample.journal balance -1 @@ -6176,7 +6247,7 @@ PART 4: COMMANDS 0 Dropping top-level accounts - You can also hide one or more top-level account name parts, using + You can also hide one or more top-level account name parts, using --drop NUM. This can be useful for hiding repetitive top-level account names: @@ -6187,53 +6258,53 @@ PART 4: COMMANDS $2 Showing declared accounts - With --declared, accounts which have been declared with an account di- - rective will be included in the balance report, even if they have no + With --declared, accounts which have been declared with an account di- + rective will be included in the balance report, even if they have no transactions. (Since they will have a zero balance, you will also need -E/--empty to see them.) - More precisely, leaf declared accounts (with no subaccounts) will be + More precisely, leaf declared accounts (with no subaccounts) will be included, since those are usually the more useful in reports. - The idea of this is to be able to see a useful "complete" balance re- + The idea of this is to be able to see a useful "complete" balance re- port, even when you don't have transactions in all of your declared ac- counts yet. Sorting by amount - With -S/--sort-amount, accounts with the largest (most positive) bal- - ances are shown first. Eg: hledger bal expenses -MAS shows your - biggest averaged monthly expenses first. When more than one commodity - is present, they will be sorted by the alphabetically earliest commod- - ity first, and then by subsequent commodities (if an amount is missing + With -S/--sort-amount, accounts with the largest (most positive) bal- + ances are shown first. Eg: hledger bal expenses -MAS shows your + biggest averaged monthly expenses first. When more than one commodity + is present, they will be sorted by the alphabetically earliest commod- + ity first, and then by subsequent commodities (if an amount is missing a commodity, it is treated as 0). - Revenues and liability balances are typically negative, however, so -S - shows these in reverse order. To work around this, you can add --in- - vert to flip the signs. (Or, use one of the higher-level reports, + Revenues and liability balances are typically negative, however, so -S + shows these in reverse order. To work around this, you can add --in- + vert to flip the signs. (Or, use one of the higher-level reports, which flip the sign automatically. Eg: hledger incomestatement -MAS). Percentages - With -%/--percent, balance reports show each account's value expressed + With -%/--percent, balance reports show each account's value expressed as a percentage of the (column) total. Note it is not useful to calculate percentages if the amounts in a col- - umn have mixed signs. In this case, make a separate report for each + umn have mixed signs. In this case, make a separate report for each sign, eg: $ hledger bal -% amt:`>0` $ hledger bal -% amt:`<0` - Similarly, if the amounts in a column have mixed commodities, convert - them to one commodity with -B, -V, -X or --value, or make a separate + Similarly, if the amounts in a column have mixed commodities, convert + them to one commodity with -B, -V, -X or --value, or make a separate report for each commodity: $ hledger bal -% cur:\\$ $ hledger bal -% cur: Multi-period balance report - With a report interval (set by the -D/--daily, -W/--weekly, - -M/--monthly, -Q/--quarterly, -Y/--yearly, or -p/--period flag), bal- - ance shows a tabular report, with columns representing successive time + With a report interval (set by the -D/--daily, -W/--weekly, + -M/--monthly, -Q/--quarterly, -Y/--yearly, or -p/--period flag), bal- + ance shows a tabular report, with columns representing successive time periods (and a title): $ hledger -f examples/sample.journal bal --quarterly income expenses -E @@ -6254,21 +6325,21 @@ PART 4: COMMANDS encompass the displayed subperiods (so that the first and last subpe- riods have the same duration as the others). - o Leading and trailing periods (columns) containing all zeroes are not + o Leading and trailing periods (columns) containing all zeroes are not shown, unless -E/--empty is used. - o Accounts (rows) containing all zeroes are not shown, unless + o Accounts (rows) containing all zeroes are not shown, unless -E/--empty is used. - o Amounts with many commodities are shown in abbreviated form, unless + o Amounts with many commodities are shown in abbreviated form, unless --no-elide is used. (experimental) - o Average and/or total columns can be added with the -A/--average and + o Average and/or total columns can be added with the -A/--average and -T/--row-total flags. o The --transpose flag can be used to exchange rows and columns. - o The --pivot FIELD option causes a different transaction field to be + o The --pivot FIELD option causes a different transaction field to be used as "account name". See PIVOTING. Multi-period reports with many periods can be too wide for easy viewing @@ -6282,57 +6353,57 @@ PART 4: COMMANDS o Reduce the terminal's font size - o View with a pager like less, eg: hledger bal -D --color=yes | less + o View with a pager like less, eg: hledger bal -D --color=yes | less -RS - o Output as CSV and use a CSV viewer like visidata (hledger bal -D -O - csv | vd -f csv), Emacs' csv-mode (M-x csv-mode, C-c C-a), or a + o Output as CSV and use a CSV viewer like visidata (hledger bal -D -O + csv | vd -f csv), Emacs' csv-mode (M-x csv-mode, C-c C-a), or a spreadsheet (hledger bal -D -o a.csv && open a.csv) - o Output as HTML and view with a browser: hledger bal -D -o a.html && + o Output as HTML and view with a browser: hledger bal -D -o a.html && open a.html Balance change, end balance - It's important to be clear on the meaning of the numbers shown in bal- + It's important to be clear on the meaning of the numbers shown in bal- ance reports. Here is some terminology we use: - A balance change is the net amount added to, or removed from, an ac- + A balance change is the net amount added to, or removed from, an ac- count during some period. - An end balance is the amount accumulated in an account as of some date - (and some time, but hledger doesn't store that; assume end of day in + An end balance is the amount accumulated in an account as of some date + (and some time, but hledger doesn't store that; assume end of day in your timezone). It is the sum of previous balance changes. - We call it a historical end balance if it includes all balance changes + We call it a historical end balance if it includes all balance changes since the account was created. For a real world account, this means it - will match the "historical record", eg the balances reported in your + will match the "historical record", eg the balances reported in your bank statements or bank web UI. (If they are correct!) - In general, balance changes are what you want to see when reviewing + In general, balance changes are what you want to see when reviewing revenues and expenses, and historical end balances are what you want to see when reviewing or reconciling asset, liability and equity accounts. - balance shows balance changes by default. To see accurate historical + balance shows balance changes by default. To see accurate historical end balances: - 1. Initialise account starting balances with an "opening balances" - transaction (a transfer from equity to the account), unless the + 1. Initialise account starting balances with an "opening balances" + transaction (a transfer from equity to the account), unless the journal covers the account's full lifetime. 2. Include all of of the account's prior postings in the report, by not - specifying a report start date, or by using the -H/--historical + specifying a report start date, or by using the -H/--historical flag. (-H causes report start date to be ignored when summing post- ings.) Balance report types - The balance command is quite flexible; here is the full detail on how - to control what it reports. If the following seems complicated, don't - worry - this is for advanced reporting, and it does take time and ex- + The balance command is quite flexible; here is the full detail on how + to control what it reports. If the following seems complicated, don't + worry - this is for advanced reporting, and it does take time and ex- perimentation to get familiar with all the report modes. There are three important option groups: - hledger balance [CALCULATIONTYPE] [ACCUMULATIONTYPE] [VALUATIONTYPE] + hledger balance [CALCULATIONTYPE] [ACCUMULATIONTYPE] [VALUATIONTYPE] ... Calculation type @@ -6344,57 +6415,57 @@ PART 4: COMMANDS each account/period) o --valuechange : show the change in period-end historical balance val- - ues (caused by deposits, withdrawals, and/or market price fluctua- + ues (caused by deposits, withdrawals, and/or market price fluctua- tions) - o --gain : show the unrealised capital gain/loss, (the current valued + o --gain : show the unrealised capital gain/loss, (the current valued balance minus each amount's original cost) o --count : show the count of postings Accumulation type - How amounts should accumulate across report periods. Another way to - say it: which time period's postings should contribute to each cell's + How amounts should accumulate across report periods. Another way to + say it: which time period's postings should contribute to each cell's calculation. It is one of: - o --change : calculate with postings from column start to column end, - ie "just this column". Typically used to see revenues/expenses. + o --change : calculate with postings from column start to column end, + ie "just this column". Typically used to see revenues/expenses. (default for balance, incomestatement) - o --cumulative : calculate with postings from report start to column - end, ie "previous columns plus this column". Typically used to show + o --cumulative : calculate with postings from report start to column + end, ie "previous columns plus this column". Typically used to show changes accumulated since the report's start date. Not often used. - o --historical/-H : calculate with postings from journal start to col- - umn end, ie "all postings from before report start date until this - column's end". Typically used to see historical end balances of as- - sets/liabilities/equity. (default for balancesheet, balancesheete- + o --historical/-H : calculate with postings from journal start to col- + umn end, ie "all postings from before report start date until this + column's end". Typically used to see historical end balances of as- + sets/liabilities/equity. (default for balancesheet, balancesheete- quity, cashflow) Valuation type - Which kind of value or cost conversion should be applied, if any, be- + Which kind of value or cost conversion should be applied, if any, be- fore displaying the report. It is one of: o no valuation type : don't convert to cost or value (default) - o --value=cost[,COMM] : convert amounts to cost (then optionally to + o --value=cost[,COMM] : convert amounts to cost (then optionally to some other commodity) - o --value=then[,COMM] : convert amounts to market value on transaction + o --value=then[,COMM] : convert amounts to market value on transaction dates - o --value=end[,COMM] : convert amounts to market value on period end + o --value=end[,COMM] : convert amounts to market value on period end date(s) (default with --valuechange, --gain) o --value=now[,COMM] : convert amounts to market value on today's date - o --value=YYYY-MM-DD[,COMM] : convert amounts to market value on an- + o --value=YYYY-MM-DD[,COMM] : convert amounts to market value on an- other date or one of the equivalent simpler flags: - o -B/--cost : like --value=cost (though, note --cost and --value are + o -B/--cost : like --value=cost (though, note --cost and --value are independent options which can both be used at once) o -V/--market : like --value=end @@ -6404,13 +6475,13 @@ PART 4: COMMANDS See Cost reporting and Value reporting for more about these. Combining balance report types - Most combinations of these options should produce reasonable reports, - but if you find any that seem wrong or misleading, let us know. The + Most combinations of these options should produce reasonable reports, + but if you find any that seem wrong or misleading, let us know. The following restrictions are applied: o --valuechange implies --value=end - o --valuechange makes --change the default when used with the bal- + o --valuechange makes --change the default when used with the bal- ancesheet/balancesheetequity commands o --cumulative or --historical disables --row-total/-T @@ -6424,26 +6495,26 @@ PART 4: COMMANDS lation:v ----------------------------------------------------------------------------------- --change change in period sum of posting- period-end DATE-value of - date market val- value of change change in pe- + date market val- value of change change in pe- ues in period in period riod - --cumu- change from re- sum of posting- period-end DATE-value of - lative port start to date market val- value of change change from + --cumu- change from re- sum of posting- period-end DATE-value of + lative port start to date market val- value of change change from period end ues from report from report report start start to period start to period to period end end end --his- change from sum of posting- period-end DATE-value of - torical journal start to date market val- value of change change from - /-H period end (his- ues from journal from journal journal start + torical journal start to date market val- value of change change from + /-H period end (his- ues from journal from journal journal start torical end bal- start to period start to period to period end ance) end end Budget report - The --budget report type activates extra columns showing any budget + The --budget report type activates extra columns showing any budget goals for each account and period. The budget goals are defined by pe- - riodic transactions. This is useful for comparing planned and actual + riodic transactions. This is useful for comparing planned and actual income, expenses, time usage, etc. - For example, you can take average monthly expenses in the common ex- + For example, you can take average monthly expenses in the common ex- pense categories to construct a minimal monthly budget: ;; Budget @@ -6488,30 +6559,30 @@ PART 4: COMMANDS ----------------------++---------------------------------------------------- || 0 [ 0] 0 [ 0] - This is different from a normal balance report in several ways. Cur- + This is different from a normal balance report in several ways. Cur- rently: - o Accounts with budget goals during the report period, and their par- + o Accounts with budget goals during the report period, and their par- ents, are shown. o Their subaccounts are not shown (regardless of the depth setting). - o Accounts without budget goals, if any, are aggregated and shown as + o Accounts without budget goals, if any, are aggregated and shown as "". - o Amounts are always inclusive (subaccount-including), even in list + o Amounts are always inclusive (subaccount-including), even in list mode. - o After each actual amount, the corresponding goal amount and percent- + o After each actual amount, the corresponding goal amount and percent- age of goal reached are also shown, in square brackets. - This means that the numbers displayed will not always add up! Eg - above, the expenses actual amount includes the gifts and supplies + This means that the numbers displayed will not always add up! Eg + above, the expenses actual amount includes the gifts and supplies transactions, but the expenses:gifts and expenses:supplies accounts are not shown, as they have no budget amounts declared. - This can be confusing. When you need to make things clearer, use the - -E/--empty flag, which will reveal all accounts including unbudgeted + This can be confusing. When you need to make things clearer, use the + -E/--empty flag, which will reveal all accounts including unbudgeted ones, giving the full picture. Eg: $ hledger balance -M --budget --empty @@ -6558,19 +6629,19 @@ PART 4: COMMANDS hledger bal -M --budget type:rx - It's also common to limit or convert them to a single currency - (cur:COMM or -X COMM [--infer-market-prices]). If showing multiple + It's also common to limit or convert them to a single currency + (cur:COMM or -X COMM [--infer-market-prices]). If showing multiple currencies, --layout bare or --layout tall can help. For more examples and notes, see Budgeting. Budget report start date - This might be a bug, but for now: when making budget reports, it's a + This might be a bug, but for now: when making budget reports, it's a good idea to explicitly set the report's start date to the first day of - a reporting period, because a periodic rule like ~ monthly generates - its transactions on the 1st of each month, and if your journal has no - regular transactions on the 1st, the default report start date could - exclude that budget goal, which can be a little surprising. Eg here + a reporting period, because a periodic rule like ~ monthly generates + its transactions on the 1st of each month, and if your journal has no + regular transactions on the 1st, the default report start date could + exclude that budget goal, which can be a little surprising. Eg here the default report period is just the day of 2020-01-15: ~ monthly in 2020 @@ -6589,9 +6660,9 @@ PART 4: COMMANDS --------------++------------ || $400 - To avoid this, specify the budget report's period, or at least the - start date, with -b/-e/-p/date:, to ensure it includes the budget goal - transactions (periodic transactions) that you want. Eg, adding -b + To avoid this, specify the budget report's period, or at least the + start date, with -b/-e/-p/date:, to ensure it includes the budget goal + transactions (periodic transactions) that you want. Eg, adding -b 2020/1/1 to the above: $ hledger bal expenses --budget -b 2020/1/1 @@ -6604,12 +6675,12 @@ PART 4: COMMANDS || $400 [80% of $500] Budgets and subaccounts - You can add budgets to any account in your account hierarchy. If you + You can add budgets to any account in your account hierarchy. If you have budgets on both parent account and some of its children, then bud- - get(s) of the child account(s) would be added to the budget of their + get(s) of the child account(s) would be added to the budget of their parent, much like account balances behave. - In the most simple case this means that once you add a budget to any + In the most simple case this means that once you add a budget to any account, all its parents would have budget as well. To illustrate this, consider the following budget: @@ -6619,13 +6690,13 @@ PART 4: COMMANDS expenses:personal:electronics $100.00 liabilities - With this, monthly budget for electronics is defined to be $100 and - budget for personal expenses is an additional $1000, which implicitly + With this, monthly budget for electronics is defined to be $100 and + budget for personal expenses is an additional $1000, which implicitly means that budget for both expenses:personal and expenses is $1100. - Transactions in expenses:personal:electronics will be counted both to- + Transactions in expenses:personal:electronics will be counted both to- wards its $100 budget and $1100 of expenses:personal , and transactions - in any other subaccount of expenses:personal would be counted towards + in any other subaccount of expenses:personal would be counted towards only towards the budget of expenses:personal. For example, let's consider these transactions: @@ -6651,9 +6722,9 @@ PART 4: COMMANDS expenses:personal $30.00 liabilities - As you can see, we have transactions in expenses:personal:electron- - ics:upgrades and expenses:personal:train tickets, and since both of - these accounts are without explicitly defined budget, these transac- + As you can see, we have transactions in expenses:personal:electron- + ics:upgrades and expenses:personal:train tickets, and since both of + these accounts are without explicitly defined budget, these transac- tions would be counted towards budgets of expenses:personal:electronics and expenses:personal accordingly: @@ -6669,7 +6740,7 @@ PART 4: COMMANDS -------------------------------++------------------------------- || 0 [ 0] - And with --empty, we can get a better picture of budget allocation and + And with --empty, we can get a better picture of budget allocation and consumption: $ hledger balance --budget -M --empty @@ -6688,29 +6759,29 @@ PART 4: COMMANDS Selecting budget goals The budget report evaluates periodic transaction rules to generate spe- - cial "goal transactions", which generate the goal amounts for each ac- - count in each report subperiod. When troubleshooting, you can use + cial "goal transactions", which generate the goal amounts for each ac- + count in each report subperiod. When troubleshooting, you can use print --forecast to show these as forecasted transactions: $ hledger print --forecast=BUDGETREPORTPERIOD tag:generated - By default, the budget report uses all available periodic transaction - rules to generate goals. This includes rules with a different report - interval from your report. Eg if you have daily, weekly and monthly - periodic rules, all of these will contribute to the goals in a monthly + By default, the budget report uses all available periodic transaction + rules to generate goals. This includes rules with a different report + interval from your report. Eg if you have daily, weekly and monthly + periodic rules, all of these will contribute to the goals in a monthly budget report. - You can select a subset of periodic rules by providing an argument to - the --budget flag. --budget=DESCPAT will match all periodic rules + You can select a subset of periodic rules by providing an argument to + the --budget flag. --budget=DESCPAT will match all periodic rules whose description contains DESCPAT, a case-insensitive substring (not a - regular expression or query). This means you can give your periodic - rules descriptions (remember that two spaces are needed), and then se- + regular expression or query). This means you can give your periodic + rules descriptions (remember that two spaces are needed), and then se- lect from multiple budgets defined in your journal. Budget vs forecast - hledger --forecast ... and hledger balance --budget ... are separate - features, though both of them use the periodic transaction rules de- - fined in the journal, and both of them generate temporary transactions + hledger --forecast ... and hledger balance --budget ... are separate + features, though both of them use the periodic transaction rules de- + fined in the journal, and both of them generate temporary transactions for reporting purposes ("forecast transactions" and "budget goal trans- actions", respectively). You can use both features at the same time if you want. Here are some differences between them, as of hledger 1.29: @@ -6726,26 +6797,26 @@ PART 4: COMMANDS o forecast transactions are visible in any report, like ordinary trans- actions - o budget goal transactions are invisible except for the goal amounts + o budget goal transactions are invisible except for the goal amounts they produce in --budget reports. Periodic transaction rules: o --forecast uses all available periodic transaction rules - o --budget uses all periodic rules (--budget) or a selected subset + o --budget uses all periodic rules (--budget) or a selected subset (--budget=DESCPAT) Period of generated transactions: o --forecast generates forecast transactions - o from after the last regular transaction to the end of the report + o from after the last regular transaction to the end of the report period (--forecast) o or, during a specified period (--forecast=PERIODEXPR) - o possibly further restricted by a period specified in the periodic + o possibly further restricted by a period specified in the periodic transaction rule o and always restricted within the bounds of the report period @@ -6754,16 +6825,16 @@ PART 4: COMMANDS o throughout the report period - o possibly restricted by a period specified in the periodic transac- + o possibly restricted by a period specified in the periodic transac- tion rule. Balance report layout - The --layout option affects how balance reports show multi-commodity - amounts and commodity symbols, which can improve readability. It can + The --layout option affects how balance reports show multi-commodity + amounts and commodity symbols, which can improve readability. It can also normalise the data for easy consumption by other programs. It has four possible values: - o --layout=wide[,WIDTH]: commodities are shown on a single line, op- + o --layout=wide[,WIDTH]: commodities are shown on a single line, op- tionally elided to WIDTH o --layout=tall: each commodity is shown on a separate line @@ -6771,10 +6842,10 @@ PART 4: COMMANDS o --layout=bare: commodity symbols are in their own column, amounts are bare numbers - o --layout=tidy: data is normalised to easily-consumed "tidy" form, + o --layout=tidy: data is normalised to easily-consumed "tidy" form, with one row per data value - Here are the --layout modes supported by each output format; note only + Here are the --layout modes supported by each output format; note only CSV output supports all of them: - txt csv html json sql @@ -6797,7 +6868,7 @@ PART 4: COMMANDS ------------------++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- || 10.00 ITOT, 337.18 USD, 12.00 VEA, 106.00 VHT 70.00 GLD, 18.00 ITOT, -98.12 USD, 10.00 VEA, 18.00 VHT -11.00 ITOT, 4881.44 USD, 14.00 VEA, 170.00 VHT 70.00 GLD, 17.00 ITOT, 5120.50 USD, 36.00 VEA, 294.00 VHT - o Limited wide layout. A width limit reduces the width, but some com- + o Limited wide layout. A width limit reduces the width, but some com- modities will be hidden: $ hledger -f examples/bcexample.hledger bal assets:us:etrade -3 -T -Y --layout=wide,32 @@ -6809,7 +6880,7 @@ PART 4: COMMANDS ------------------++--------------------------------------------------------------------------------------------------------------------------- || 10.00 ITOT, 337.18 USD, 2 more.. 70.00 GLD, 18.00 ITOT, 3 more.. -11.00 ITOT, 3 more.. 70.00 GLD, 17.00 ITOT, 3 more.. - o Tall layout. Each commodity gets a new line (may be different in + o Tall layout. Each commodity gets a new line (may be different in each column), and account names are repeated: $ hledger -f examples/bcexample.hledger bal assets:us:etrade -3 -T -Y --layout=tall @@ -6829,7 +6900,7 @@ PART 4: COMMANDS || 106.00 VHT 10.00 VEA 170.00 VHT 36.00 VEA || 18.00 VHT 294.00 VHT - o Bare layout. Commodity symbols are kept in one column, each commod- + o Bare layout. Commodity symbols are kept in one column, each commod- ity gets its own report row, account names are repeated: $ hledger -f examples/bcexample.hledger bal assets:us:etrade -3 -T -Y --layout=bare @@ -6849,7 +6920,7 @@ PART 4: COMMANDS || VEA 12.00 10.00 14.00 36.00 || VHT 106.00 18.00 170.00 294.00 - o Bare layout also affects CSV output, which is useful for producing + o Bare layout also affects CSV output, which is useful for producing data that is easier to consume, eg for making charts: $ hledger -f examples/bcexample.hledger bal assets:us:etrade -3 -O csv --layout=bare @@ -6867,11 +6938,11 @@ PART 4: COMMANDS o Note: bare layout will sometimes display an extra row for the no-sym- bol commodity, because of zero amounts (hledger treats zeroes as com- - modity-less, usually). This can break hledger-bar confusingly + modity-less, usually). This can break hledger-bar confusingly (workaround: add a cur: query to exclude the no-symbol row). o Tidy layout produces normalised "tidy data", where every variable has - its own column and each row represents a single data point. See + its own column and each row represents a single data point. See https://cran.r-project.org/web/packages/tidyr/vignettes/tidy- data.html for more. This is the easiest kind of data for other soft- ware to consume. Here's how it looks: @@ -6898,25 +6969,25 @@ PART 4: COMMANDS Some frequently used balance options/reports are: o bal -M revenues expenses - Show revenues/expenses in each month. Also available as the incomes- + Show revenues/expenses in each month. Also available as the incomes- tatement command. o bal -M -H assets liabilities - Show historical asset/liability balances at each month end. Also + Show historical asset/liability balances at each month end. Also available as the balancesheet command. o bal -M -H assets liabilities equity - Show historical asset/liability/equity balances at each month end. + Show historical asset/liability/equity balances at each month end. Also available as the balancesheetequity command. o bal -M assets not:receivable - Show changes to liquid assets in each month. Also available as the + Show changes to liquid assets in each month. Also available as the cashflow command. Also: o bal -M expenses -2 -SA - Show monthly expenses summarised to depth 2 and sorted by average + Show monthly expenses summarised to depth 2 and sorted by average amount. o bal -M --budget expenses @@ -6932,14 +7003,14 @@ PART 4: COMMANDS balancesheet (bs) - This command displays a balance sheet, showing historical ending bal- + This command displays a balance sheet, showing historical ending bal- ances of asset and liability accounts. (To see equity as well, use the - balancesheetequity command.) Amounts are shown with normal positive + balancesheetequity command.) Amounts are shown with normal positive sign, as in conventional financial statements. - This report shows accounts declared with the Asset, Cash or Liability - type (see account types). Or if no such accounts are declared, it - shows top-level accounts named asset or liability (case insensitive, + This report shows accounts declared with the Asset, Cash or Liability + type (see account types). Or if no such accounts are declared, it + shows top-level accounts named asset or liability (case insensitive, plurals allowed) and their subaccounts. Example: @@ -6964,14 +7035,14 @@ PART 4: COMMANDS 0 This command is a higher-level variant of the balance command, and sup- - ports many of that command's features, such as multi-period reports. - It is similar to hledger balance -H assets liabilities, but with - smarter account detection, and liabilities displayed with their sign + ports many of that command's features, such as multi-period reports. + It is similar to hledger balance -H assets liabilities, but with + smarter account detection, and liabilities displayed with their sign flipped. This command also supports the output destination and output format op- - tions The output formats supported are txt, csv, html, and (experimen- - tal) json. + tions The output formats supported are txt, csv, tsv, html, and (exper- + imental) json. balancesheetequity (bse) @@ -7018,21 +7089,21 @@ PART 4: COMMANDS sign flipped. This command also supports the output destination and output format op- - tions The output formats supported are txt, csv, html, and (experimen- - tal) json. + tions The output formats supported are txt, csv, tsv, html, and (exper- + imental) json. cashflow (cf) - This command displays a cashflow statement, showing the inflows and - outflows affecting "cash" (ie, liquid, easily convertible) assets. - Amounts are shown with normal positive sign, as in conventional finan- + This command displays a cashflow statement, showing the inflows and + outflows affecting "cash" (ie, liquid, easily convertible) assets. + Amounts are shown with normal positive sign, as in conventional finan- cial statements. - This report shows accounts declared with the Cash type (see account + This report shows accounts declared with the Cash type (see account types). Or if no such accounts are declared, it shows accounts - o under a top-level account named asset (case insensitive, plural al- + o under a top-level account named asset (case insensitive, plural al- lowed) o whose name contains some variation of cash, bank, checking or saving. @@ -7061,13 +7132,13 @@ PART 4: COMMANDS $-1 This command is a higher-level variant of the balance command, and sup- - ports many of that command's features, such as multi-period reports. - It is similar to hledger balance assets not:fixed not:investment + ports many of that command's features, such as multi-period reports. + It is similar to hledger balance assets not:fixed not:investment not:receivable, but with smarter account detection. This command also supports the output destination and output format op- - tions The output formats supported are txt, csv, html, and (experimen- - tal) json. + tions The output formats supported are txt, csv, tsv, html, and (exper- + imental) json. check Check for various kinds of errors in your data. @@ -7481,57 +7552,59 @@ PART 4: COMMANDS $ hledger help -m journal # show it with man, even if info is installed import - Read new transactions added to each FILE since last run, and add them - to the journal. Or with --dry-run, just print the transactions that - would be added. Or with --catchup, just mark all of the FILEs' trans- - actions as imported, without actually importing any. + Read new transactions added to each FILE provided as arguments since + last run, and add them to the journal. Or with --dry-run, just print + the transactions that would be added. Or with --catchup, just mark all + of the FILEs' current transactions as imported, without importing them. - This command may append new transactions to the main journal file - (which should be in journal format). Existing transactions are not - changed. This is one of the few hledger commands that writes to the + This command may append new transactions to the main journal file + (which should be in journal format). Existing transactions are not + changed. This is one of the few hledger commands that writes to the journal file (see also add). - Unlike other hledger commands, with import the journal file is an out- + Unlike other hledger commands, with import the journal file is an out- put file, and will be modified, though only by appending (existing data - will not be changed). The input files are specified as arguments, so - to import one or more CSV files to your main journal, you will run + will not be changed). The input files are specified as arguments, so + to import one or more CSV files to your main journal, you will run hledger import bank.csv or perhaps hledger import *.csv. Note you can import from any file format, though CSV files are the most common import source, and these docs focus on that case. Deduplication - As a convenience import does deduplication while reading transactions. - This does not mean "ignore transactions that look the same", but rather - "ignore transactions that have been seen before". This is intended for - when you are periodically importing foreign data which may contain al- - ready-imported transactions. So eg, if every day you download bank CSV - files containing redundant data, you can safely run hledger import - bank.csv and only new transactions will be imported. (import is idem- - potent.) + import does time-based deduplication, to detect only the new transac- + tions since the last successful import. (This does not mean "ignore + transactions that look the same", but rather "ignore transactions that + have been seen before".) This is intended for when you are periodi- + cally importing downloaded data, which may overlap with previous down- + loads. Eg if every week (or every day) you download a bank's last + three months of CSV data, you can safely run hledger import thebank.csv + each time and only new transactions will be imported. - Since the items being read (CSV records, eg) often do not come with - unique identifiers, hledger detects new transactions by date, assuming + Since the items being read (CSV records, eg) often do not come with + unique identifiers, hledger detects new transactions by date, assuming that: 1. new items always have the newest dates 2. item dates do not change across reads - 3. and items with the same date remain in the same relative order + 3. and items with the same date remain in the same relative order across reads. - These are often true of CSV files representing transactions, or true - enough so that it works pretty well in practice. 1 is important, but + These are often true of CSV files representing transactions, or true + enough so that it works pretty well in practice. 1 is important, but violations of 2 and 3 amongst the old transactions won't matter (and if - you import often, the new transactions will be few, so less likely to + you import often, the new transactions will be few, so less likely to be the ones affected). - hledger remembers the latest date processed in each input file by sav- - ing a hidden ".latest" state file in the same directory. Eg when read- - ing finance/bank.csv, it will look for and update the finance/.lat- - est.bank.csv state file. The format is simple: one or more lines con- - taining the same ISO-format date (YYYY-MM-DD), meaning "I have + hledger remembers the latest date processed in each input file by sav- + ing a hidden ".latest.FILE" file in FILE's directory (after a succesful + import). + + Eg when reading finance/bank.csv, it will look for and update the fi- + nance/.latest.bank.csv state file. The format is simple: one or more + lines containing the same ISO-format date (YYYY-MM-DD), meaning "I have processed transactions up to this date, and this many of them on that date." Normally you won't see or manipulate these state files yourself. But if needed, you can delete them to reset the state (making all @@ -7622,15 +7695,15 @@ PART 4: COMMANDS sign flipped. This command also supports the output destination and output format op- - tions The output formats supported are txt, csv, html, and (experimen- - tal) json. + tions The output formats supported are txt, csv, tsv, html, and (exper- + imental) json. notes List the unique notes that appear in transactions. This command lists the unique notes that appear in transactions, in al- - phabetic order. You can add a query to select a subset of transac- - tions. The note is the part of the transaction description after a | + phabetic order. You can add a query to select a subset of transac- + tions. The note is the part of the transaction description after a | character (or if there is no |, the whole description). Example: @@ -7642,14 +7715,14 @@ PART 4: COMMANDS payees List the unique payee/payer names that appear in transactions. - This command lists unique payee/payer names which have been declared - with payee directives (--declared), used in transaction descriptions + This command lists unique payee/payer names which have been declared + with payee directives (--declared), used in transaction descriptions (--used), or both (the default). - The payee/payer is the part of the transaction description before a | + The payee/payer is the part of the transaction description before a | character (or if there is no |, the whole description). - You can add query arguments to select a subset of transactions. This + You can add query arguments to select a subset of transactions. This implies --used. Example: @@ -7660,11 +7733,20 @@ PART 4: COMMANDS Person A prices - Print market price directives from the journal. With --infer-market- - prices, generate additional market prices from costs. With --infer-re- - verse-prices, also generate market prices by inverting known prices. - Prices can be filtered by a query. Price amounts are displayed with - their full precision. + Print the market prices declared with P directives. With --infer-mar- + ket-prices, also show any additional prices inferred from costs. With + --show-reverse, also show additional prices inferred by reversing known + prices. + + Price amounts are always displayed with their full precision, except + for reverse prices which are limited to 8 decimal digits. + + Prices can be filtered by a date:, cur: or amt: query. + + Generally if you run this command with --infer-market-prices --show-re- + verse, it will show the same prices used internally to calculate value + reports. But if in doubt, you can inspect those directly by running + the value report with --debug=2. print Show transaction journal entries, sorted by date. @@ -7672,26 +7754,14 @@ PART 4: COMMANDS The print command displays full journal entries (transactions) from the journal file, sorted by date (or with --date2, by secondary date). - Amounts are shown mostly normalised to commodity display style, eg the - placement of commodity symbols will be consistent. All of their deci- - mal places are shown, as in the original journal entry (with one alter- - ation: in some cases trailing zeroes are added.) - - Amounts are shown right-aligned within each transaction (but not across - all transactions). - - Directives and inter-transaction comments are not shown, currently. + Directives and inter-transaction comments are not shown, currently. This means the print command is somewhat lossy, and if you are using it - to reformat your journal you should take care to also copy over the di- - rectives and file-level comments. + to reformat/regenerate your journal you should take care to also copy + over the directives and inter-transaction comments. Eg: - $ hledger print - 2008/01/01 income - assets:bank:checking $1 - income:salary $-1 - + $ hledger print -f examples/sample.journal date:200806 2008/06/01 gift assets:bank:checking $1 income:gifts $-1 @@ -7705,13 +7775,56 @@ PART 4: COMMANDS expenses:supplies $1 assets:cash $-2 - 2008/12/31 * pay off - liabilities:debts $1 - assets:bank:checking $-1 + print explicitness + Normally, whether posting amounts are implicit or explicit is pre- + served. For example, when an amount is omitted in the journal, it will + not appear in the output. Similarly, if a conversion cost is implied + but not written, it will not appear in the output. + You can use the -x/--explicit flag to force explicit display of all + amounts and costs. This can be useful for troubleshooting or for mak- + ing your journal more readable and robust against data entry errors. + -x is also implied by using any of -B,-V,-X,--value. + + The -x/--explicit flag will cause any postings with a multi-commodity + amount (which can arise when a multi-commodity transaction has an im- + plicit amount) to be split into multiple single-commodity postings, + keeping the output parseable. + + print amount style + Amounts are shown right-aligned within each transaction (but not + aligned across all transactions; you can do that with ledger-mode in + Emacs). + + Amounts will be (mostly) normalised to their commodity display style: + their symbol placement, decimal mark, and digit group marks will be + made consistent. By default, decimal digits are shown as they are + written in the journal. + + With the --round option, print will try increasingly hard to display + decimal digits according to the commodity display styles: + + o --round=none show amounts with original precisions (default) + + o --round=soft add/remove decimal zeros in amounts (except costs) + + o --round=hard round amounts (except costs), possibly hiding signifi- + cant digits + + o --round=all round all amounts and costs + + soft is good for non-lossy cleanup, formatting amounts more consis- + tently where it's safe to do so. + + hard and all can cause print to show invalid unbalanced journal en- + tries; they may be useful eg for stronger cleanup, with manual fixups + when needed. + + print parseability print's output is usually a valid hledger journal, and you can process it again with a second hledger command. This can be useful for certain - kinds of search, eg: + kinds of search (though the same can be achieved with expr: queries + now): # Show running total of food expenses paid from cash. # -f- reads from stdin. -I/--ignore-assertions is sometimes needed. @@ -7719,43 +7832,48 @@ PART 4: COMMANDS There are some situations where print's output can become unparseable: - o Value reporting affects posting amounts but not balance assertion or + o Value reporting affects posting amounts but not balance assertion or balance assignment amounts, potentially causing those to fail. o Auto postings can generate postings with too many missing amounts. o Account aliases can generate bad account names. - Normally, the journal entry's explicit or implicit amount style is pre- - served. For example, when an amount is omitted in the journal, it will - not appear in the output. Similarly, when a cost is implied but not - written, it will not appear in the output. You can use the -x/--ex- - plicit flag to make all amounts and costs explicit, which can be useful - for troubleshooting or for making your journal more readable and robust - against data entry errors. -x is also implied by using any of - -B,-V,-X,--value. + print, other features + With -B/--cost, amounts with costs are shown converted to cost. - Note, -x/--explicit will cause postings with a multi-commodity amount - (these can arise when a multi-commodity transaction has an implicit - amount) to be split into multiple single-commodity postings, keeping - the output parseable. + With --new, print shows only transactions it has not seen on a previous + run. This uses the same deduplication system as the import command. + (See import's docs for details.) - With -B/--cost, amounts with costs are converted to cost using that - price. This can be used for troubleshooting. - - With -m DESC/--match=DESC, print does a fuzzy search for one recent - transaction whose description is most similar to DESC. DESC should - contain at least two characters. If there is no similar-enough match, - no transaction will be shown and the program exit code will be non- - zero. - - With --new, hledger prints only transactions it has not seen on a pre- - vious run. This uses the same deduplication system as the import com- - mand. (See import's docs for details.) + With -m DESC/--match=DESC, print shows one recent transaction whose de- + scription is most similar to DESC. DESC should contain at least two + characters. If there is no similar-enough match, no transaction will + be shown and the program exit code will be non-zero. + print output format This command also supports the output destination and output format op- - tions The output formats supported are txt, csv, and (experimental) - json and sql. + tions The output formats supported are txt, beancount, csv, tsv, json + and sql. + + Experimental: The beancount format tries to produce Beancount-compati- + ble output. It is very basic and may require additional manual fixups: + + o Transaction and postings with unmarked status are converted to + cleared (`*``) status. + + o Transactions' payee and or note are wrapped in double quotes. + + o Transaction tags are copied to Beancount #tag format. + + o Account name parts are capitalised, and if the first account name + part is not one of Assets, Liabilities, Equity, Income, or Expenses, + "Equity:" is prepended. + + o The $ commodity symbol is converted to USD. + + o An open directive is generated for each account used, on the earliest + transaction date. Here's an example of print's CSV output: @@ -7773,20 +7891,20 @@ PART 4: COMMANDS "5","2008/12/31","","*","","pay off","","liabilities:debts","1","$","","1","","" "5","2008/12/31","","*","","pay off","","assets:bank:checking","-1","$","1","","","" - o There is one CSV record per posting, with the parent transaction's + o There is one CSV record per posting, with the parent transaction's fields repeated. o The "txnidx" (transaction index) field shows which postings belong to - the same transaction. (This number might change if transactions are - reordered within the file, files are parsed/included in a different + the same transaction. (This number might change if transactions are + reordered within the file, files are parsed/included in a different order, etc.) - o The amount is separated into "commodity" (the symbol) and "amount" + o The amount is separated into "commodity" (the symbol) and "amount" (numeric quantity) fields. o The numeric amount is repeated in either the "credit" or "debit" col- - umn, for convenience. (Those names are not accurate in the account- - ing sense; it just puts negative amounts under credit and zero or + umn, for convenience. (Those names are not accurate in the account- + ing sense; it just puts negative amounts under credit and zero or greater amounts under debit.) register @@ -7795,14 +7913,14 @@ PART 4: COMMANDS Show postings and their running total. The register command displays matched postings, across all accounts, in - date order, with their running total or running historical balance. - (See also the aregister command, which shows matched transactions in a + date order, with their running total or running historical balance. + (See also the aregister command, which shows matched transactions in a specific account.) register normally shows line per posting, but note that multi-commodity amounts will occupy multiple lines (one line per commodity). - It is typically used with a query selecting a particular account, to + It is typically used with a query selecting a particular account, to see that account's activity: $ hledger register checking @@ -7813,14 +7931,14 @@ PART 4: COMMANDS With --date2, it shows and sorts by secondary date instead. - For performance reasons, column widths are chosen based on the first - 1000 lines; this means unusually wide values in later lines can cause - visual discontinuities as column widths are adjusted. If you want to - ensure perfect alignment, at the cost of more time and memory, use the + For performance reasons, column widths are chosen based on the first + 1000 lines; this means unusually wide values in later lines can cause + visual discontinuities as column widths are adjusted. If you want to + ensure perfect alignment, at the cost of more time and memory, use the --align-all flag. - The --historical/-H flag adds the balance from any undisplayed prior - postings to the running total. This is useful when you want to see + The --historical/-H flag adds the balance from any undisplayed prior + postings to the running total. This is useful when you want to see only recent activity, with a historically accurate running balance: $ hledger register checking -b 2008/6 --historical @@ -7830,18 +7948,18 @@ PART 4: COMMANDS The --depth option limits the amount of sub-account detail displayed. - The --average/-A flag shows the running average posting amount instead + The --average/-A flag shows the running average posting amount instead of the running total (so, the final number displayed is the average for - the whole report period). This flag implies --empty (see below). It - is affected by --historical. It works best when showing just one ac- + the whole report period). This flag implies --empty (see below). It + is affected by --historical. It works best when showing just one ac- count and one commodity. - The --related/-r flag shows the other postings in the transactions of + The --related/-r flag shows the other postings in the transactions of the postings which would normally be shown. - The --invert flag negates all amounts. For example, it can be used on + The --invert flag negates all amounts. For example, it can be used on an income account where amounts are normally displayed as negative num- - bers. It's also useful to show postings on the checking account to- + bers. It's also useful to show postings on the checking account to- gether with the related account: $ hledger register --related --invert assets:checking @@ -7853,7 +7971,7 @@ PART 4: COMMANDS 2008/01 income:salary $-1 $-1 2008/06 income:gifts $-1 $-2 - Periods with no activity, and summary postings with a zero amount, are + Periods with no activity, and summary postings with a zero amount, are not shown by default; use the --empty/-E flag to see them: $ hledger register --monthly income -E @@ -7870,7 +7988,7 @@ PART 4: COMMANDS 2008/11 0 $-2 2008/12 0 $-2 - Often, you'll want to see just one line per interval. The --depth op- + Often, you'll want to see just one line per interval. The --depth op- tion helps with this, causing subaccounts to be aggregated: $ hledger register --monthly assets --depth 1h @@ -7878,22 +7996,22 @@ PART 4: COMMANDS 2008/06 assets $-1 0 2008/12 assets $-1 $-1 - Note when using report intervals, if you specify start/end dates these - will be adjusted outward if necessary to contain a whole number of in- - tervals. This ensures that the first and last intervals are full + Note when using report intervals, if you specify start/end dates these + will be adjusted outward if necessary to contain a whole number of in- + tervals. This ensures that the first and last intervals are full length and comparable to the others in the report. - With -m DESC/--match=DESC, register does a fuzzy search for one recent + With -m DESC/--match=DESC, register does a fuzzy search for one recent posting whose description is most similar to DESC. DESC should contain at least two characters. If there is no similar-enough match, no post- ing will be shown and the program exit code will be non-zero. Custom register output - register uses the full terminal width by default, except on windows. - You can override this by setting the COLUMNS environment variable (not + register uses the full terminal width by default, except on windows. + You can override this by setting the COLUMNS environment variable (not a bash shell variable) or by using the --width/-w option. - The description and account columns normally share the space equally + The description and account columns normally share the space equally (about half of (width - 40) each). You can adjust this by adding a de- scription width as part of --width's argument, comma-separated: --width W,D . Here's a diagram (won't display correctly in --help): @@ -7912,18 +8030,18 @@ PART 4: COMMANDS $ hledger reg -w $COLUMNS,40 # use terminal width, & description width 40 This command also supports the output destination and output format op- - tions The output formats supported are txt, csv, and (experimental) - json. + tions The output formats supported are txt, csv, tsv, and (experimen- + tal) json. rewrite Print all transactions, rewriting the postings of matched transactions. - For now the only rewrite available is adding new postings, like print + For now the only rewrite available is adding new postings, like print --auto. This is a start at a generic rewriter of transaction entries. It reads - the default journal and prints the transactions, like print, but adds + the default journal and prints the transactions, like print, but adds one or more specified postings to any transactions matching QUERY. The - posting amounts can be fixed, or a multiplier of the existing transac- + posting amounts can be fixed, or a multiplier of the existing transac- tion's first posting amount. Examples: @@ -7939,7 +8057,7 @@ PART 4: COMMANDS (reserve:grocery) *0.25 ; reserve 25% for grocery (reserve:) *0.25 ; reserve 25% for grocery - Note the single quotes to protect the dollar sign from bash, and the + Note the single quotes to protect the dollar sign from bash, and the two spaces between account and amount. More: @@ -7949,16 +8067,16 @@ PART 4: COMMANDS $ hledger rewrite -- expenses:gifts --add-posting '(budget:gifts) *-1"' $ hledger rewrite -- ^income --add-posting '(budget:foreign currency) *0.25 JPY; diversify' - Argument for --add-posting option is a usual posting of transaction - with an exception for amount specification. More precisely, you can + Argument for --add-posting option is a usual posting of transaction + with an exception for amount specification. More precisely, you can use '*' (star symbol) before the amount to indicate that that this is a - factor for an amount of original matched posting. If the amount in- + factor for an amount of original matched posting. If the amount in- cludes a commodity name, the new posting amount will be in the new com- - modity; otherwise, it will be in the matched posting amount's commod- + modity; otherwise, it will be in the matched posting amount's commod- ity. Re-write rules in a file - During the run this tool will execute so called "Automated Transac- + During the run this tool will execute so called "Automated Transac- tions" found in any journal it process. I.e instead of specifying this operations in command line you can put them in a journal file. @@ -7973,7 +8091,7 @@ PART 4: COMMANDS budget:gifts *-1 assets:budget *1 - Note that '=' (equality symbol) that is used instead of date in trans- + Note that '=' (equality symbol) that is used instead of date in trans- actions you usually write. It indicates the query by which you want to match the posting to add new ones. @@ -7986,12 +8104,12 @@ PART 4: COMMANDS --add-posting 'assets:budget *1' \ > rewritten-tidy-output.journal - It is important to understand that relative order of such entries in - journal is important. You can re-use result of previously added post- + It is important to understand that relative order of such entries in + journal is important. You can re-use result of previously added post- ings. Diff output format - To use this tool for batch modification of your journal files you may + To use this tool for batch modification of your journal files you may find useful output in form of unified diff. $ hledger rewrite -- --diff -f examples/sample.journal '^income' --add-posting '(liabilities:tax) *.33' @@ -8015,10 +8133,10 @@ PART 4: COMMANDS If you'll pass this through patch tool you'll get transactions contain- ing the posting that matches your query be updated. Note that multiple - files might be update according to list of input files specified via + files might be update according to list of input files specified via --file options and include directives inside of these files. - Be careful. Whole transaction being re-formatted in a style of output + Be careful. Whole transaction being re-formatted in a style of output from hledger print. See also: @@ -8026,55 +8144,55 @@ PART 4: COMMANDS https://github.com/simonmichael/hledger/issues/99 rewrite vs. print --auto - This command predates print --auto, and currently does much the same + This command predates print --auto, and currently does much the same thing, but with these differences: - o with multiple files, rewrite lets rules in any file affect all other - files. print --auto uses standard directive scoping; rules affect + o with multiple files, rewrite lets rules in any file affect all other + files. print --auto uses standard directive scoping; rules affect only child files. - o rewrite's query limits which transactions can be rewritten; all are + o rewrite's query limits which transactions can be rewritten; all are printed. print --auto's query limits which transactions are printed. - o rewrite applies rules specified on command line or in the journal. + o rewrite applies rules specified on command line or in the journal. print --auto applies rules specified in the journal. roi - Shows the time-weighted (TWR) and money-weighted (IRR) rate of return + Shows the time-weighted (TWR) and money-weighted (IRR) rate of return on your investments. - At a minimum, you need to supply a query (which could be just an ac- - count name) to select your investment(s) with --inv, and another query + At a minimum, you need to supply a query (which could be just an ac- + count name) to select your investment(s) with --inv, and another query to identify your profit and loss transactions with --pnl. - If you do not record changes in the value of your investment manually, - or do not require computation of time-weighted return (TWR), --pnl + If you do not record changes in the value of your investment manually, + or do not require computation of time-weighted return (TWR), --pnl could be an empty query (--pnl "" or --pnl STR where STR does not match any of your accounts). - This command will compute and display the internalized rate of return - (IRR, also known as money-weighted rate of return) and time-weighted - rate of return (TWR) for your investments for the time period re- - quested. IRR is always annualized due to the way it is computed, but - TWR is reported both as a rate over the chosen reporting period and as + This command will compute and display the internalized rate of return + (IRR, also known as money-weighted rate of return) and time-weighted + rate of return (TWR) for your investments for the time period re- + quested. IRR is always annualized due to the way it is computed, but + TWR is reported both as a rate over the chosen reporting period and as an annual rate. - Price directives will be taken into account if you supply appropriate + Price directives will be taken into account if you supply appropriate --cost or --value flags (see VALUATION). Note, in some cases this report can fail, for these reasons: - o Error (NotBracketed): No solution for Internal Rate of Return (IRR). - Possible causes: IRR is huge (>1000000%), balance of investment be- + o Error (NotBracketed): No solution for Internal Rate of Return (IRR). + Possible causes: IRR is huge (>1000000%), balance of investment be- comes negative at some point in time. - o Error (SearchFailed): Failed to find solution for Internal Rate of + o Error (SearchFailed): Failed to find solution for Internal Rate of Return (IRR). Either search does not converge to a solution, or con- verges too slowly. Examples: - o Using roi to compute total return of investment in stocks: + o Using roi to compute total return of investment in stocks: https://github.com/simonmichael/hledger/blob/master/examples/invest- ing/roi-unrealised.ledger @@ -8084,28 +8202,28 @@ PART 4: COMMANDS Note that --inv and --pnl's argument is a query, and queries could have several space-separated terms (see QUERIES). - To indicate that all search terms form single command-line argument, + To indicate that all search terms form single command-line argument, you will need to put them in quotes (see Special characters): $ hledger roi --inv 'term1 term2 term3 ...' - If any query terms contain spaces themselves, you will need an extra + If any query terms contain spaces themselves, you will need an extra level of nested quoting, eg: $ hledger roi --inv="'Assets:Test 1'" --pnl="'Equity:Unrealized Profit and Loss'" Semantics of --inv and --pnl - Query supplied to --inv has to match all transactions that are related + Query supplied to --inv has to match all transactions that are related to your investment. Transactions not matching --inv will be ignored. In these transactions, ROI will conside postings that match --inv to be - "investment postings" and other postings (not matching --inv) will be - sorted into two categories: "cash flow" and "profit and loss", as ROI - needs to know which part of the investment value is your contributions + "investment postings" and other postings (not matching --inv) will be + sorted into two categories: "cash flow" and "profit and loss", as ROI + needs to know which part of the investment value is your contributions and which is due to the return on investment. o "Cash flow" is depositing or withdrawing money, buying or selling as- - sets, or otherwise converting between your investment commodity and + sets, or otherwise converting between your investment commodity and any other commodity. Example: 2019-01-01 Investing in Snake Oil @@ -8122,12 +8240,12 @@ PART 4: COMMANDS investment:snake oil = $57 equity:unrealized profit or loss - All non-investment postings are assumed to be "cash flow", unless they - match --pnl query. Changes in value of your investment due to "profit - and loss" postings will be considered as part of your investment re- + All non-investment postings are assumed to be "cash flow", unless they + match --pnl query. Changes in value of your investment due to "profit + and loss" postings will be considered as part of your investment re- turn. - Example: if you use --inv snake --pnl equity:unrealized, then postings + Example: if you use --inv snake --pnl equity:unrealized, then postings in the example below would be classifed as: 2019-01-01 Snake Oil #1 @@ -8144,57 +8262,57 @@ PART 4: COMMANDS snake oil $50 ; investment posting IRR and TWR explained - "ROI" stands for "return on investment". Traditionally this was com- - puted as a difference between current value of investment and its ini- + "ROI" stands for "return on investment". Traditionally this was com- + puted as a difference between current value of investment and its ini- tial value, expressed in percentage of the initial value. However, this approach is only practical in simple cases, where invest- - ments receives no in-flows or out-flows of money, and where rate of + ments receives no in-flows or out-flows of money, and where rate of growth is fixed over time. For more complex scenarios you need differ- - ent ways to compute rate of return, and this command implements two of + ent ways to compute rate of return, and this command implements two of them: IRR and TWR. - Internal rate of return, or "IRR" (also called "money-weighted rate of - return") takes into account effects of in-flows and out-flows, and the - time between them. Investment at a particular fixed interest rate is - going to give you more interest than the same amount invested at the - same interest rate, but made later in time. If you are withdrawing - from your investment, your future gains would be smaller (in absolute - numbers), and will be a smaller percentage of your initial investment, + Internal rate of return, or "IRR" (also called "money-weighted rate of + return") takes into account effects of in-flows and out-flows, and the + time between them. Investment at a particular fixed interest rate is + going to give you more interest than the same amount invested at the + same interest rate, but made later in time. If you are withdrawing + from your investment, your future gains would be smaller (in absolute + numbers), and will be a smaller percentage of your initial investment, so your IRR will be smaller. And if you are adding to your investment, you will receive bigger absolute gains, which will be a bigger percent- age of your initial investment, so your IRR will be larger. - As mentioned before, in-flows and out-flows would be any cash that you + As mentioned before, in-flows and out-flows would be any cash that you personally put in or withdraw, and for the "roi" command, these are the - postings that match the query in the--inv argument and NOT match the + postings that match the query in the--inv argument and NOT match the query in the--pnl argument. - If you manually record changes in the value of your investment as - transactions that balance them against "profit and loss" (or "unreal- - ized gains") account or use price directives, then in order for IRR to - compute the precise effect of your in-flows and out-flows on the rate - of return, you will need to record the value of your investement on or + If you manually record changes in the value of your investment as + transactions that balance them against "profit and loss" (or "unreal- + ized gains") account or use price directives, then in order for IRR to + compute the precise effect of your in-flows and out-flows on the rate + of return, you will need to record the value of your investement on or close to the days when in- or out-flows occur. - In technical terms, IRR uses the same approach as computation of net + In technical terms, IRR uses the same approach as computation of net present value, and tries to find a discount rate that makes net present value of all the cash flows of your investment to add up to zero. This - could be hard to wrap your head around, especially if you haven't done + could be hard to wrap your head around, especially if you haven't done discounted cash flow analysis before. Implementation of IRR in hledger should produce results that match the =XIRR formula in Excel. - Second way to compute rate of return that roi command implements is - called "time-weighted rate of return" or "TWR". Like IRR, it will ac- - count for the effect of your in-flows and out-flows, but unlike IRR it - will try to compute the true rate of return of the underlying asset, - compensating for the effect that deposits and withdrawas have on the + Second way to compute rate of return that roi command implements is + called "time-weighted rate of return" or "TWR". Like IRR, it will ac- + count for the effect of your in-flows and out-flows, but unlike IRR it + will try to compute the true rate of return of the underlying asset, + compensating for the effect that deposits and withdrawas have on the apparent rate of growth of your investment. - TWR represents your investment as an imaginary "unit fund" where in- - flows/ out-flows lead to buying or selling "units" of your investment + TWR represents your investment as an imaginary "unit fund" where in- + flows/ out-flows lead to buying or selling "units" of your investment and changes in its value change the value of "investment unit". Change - in "unit price" over the reporting period gives you rate of return of + in "unit price" over the reporting period gives you rate of return of your investment, and make TWR less sensitive than IRR to the effects of cash in-flows and out-flows. @@ -8208,21 +8326,21 @@ PART 4: COMMANDS o IRR vs TWR - o Examples of computing IRR and TWR and discussion of the limitations + o Examples of computing IRR and TWR and discussion of the limitations of both metrics stats Show journal and performance statistics. - The stats command displays summary information for the whole journal, - or a matched part of it. With a reporting interval, it shows a report + The stats command displays summary information for the whole journal, + or a matched part of it. With a reporting interval, it shows a report for each report period. - At the end, it shows (in the terminal) the overall run time and number - of transactions processed per second. Note these are approximate and - will vary based on machine, current load, data size, hledger version, - haskell lib versions, GHC version.. but they may be of interest. The - stats command's run time is similar to that of a single-column balance + At the end, it shows (in the terminal) the overall run time and number + of transactions processed per second. Note these are approximate and + will vary based on machine, current load, data size, hledger version, + haskell lib versions, GHC version.. but they may be of interest. The + stats command's run time is similar to that of a single-column balance report. Example: @@ -8252,35 +8370,35 @@ PART 4: COMMANDS This command lists the tag names used in the journal, whether on trans- actions, postings, or account declarations. - With a TAGREGEX argument, only tag names matching this regular expres- + With a TAGREGEX argument, only tag names matching this regular expres- sion (case insensitive, infix matched) are shown. - With QUERY arguments, only transactions and accounts matching this + With QUERY arguments, only transactions and accounts matching this query are considered. If the query involves transaction fields (date:, desc:, amt:, ...), the search is restricted to the matched transactions and their accounts. - With the --values flag, the tags' unique non-empty values are listed + With the --values flag, the tags' unique non-empty values are listed instead. With -E/--empty, blank/empty values are also shown. - With --parsed, tags or values are shown in the order they were parsed, - with duplicates included. (Except, tags from account declarations are + With --parsed, tags or values are shown in the order they were parsed, + with duplicates included. (Except, tags from account declarations are always shown first.) - Tip: remember, accounts also acquire tags from their parents, postings + Tip: remember, accounts also acquire tags from their parents, postings also acquire tags from their account and transaction, transactions also acquire tags from their postings. test Run built-in unit tests. - This command runs the unit tests built in to hledger and hledger-lib, - printing the results on stdout. If any test fails, the exit code will + This command runs the unit tests built in to hledger and hledger-lib, + printing the results on stdout. If any test fails, the exit code will be non-zero. - This is mainly used by hledger developers, but you can also use it to - sanity-check the installed hledger executable on your platform. All - tests are expected to pass - if you ever see a failure, please report + This is mainly used by hledger developers, but you can also use it to + sanity-check the installed hledger executable on your platform. All + tests are expected to pass - if you ever see a failure, please report as a bug! This command also accepts tasty test runner options, written after a -- @@ -8289,11 +8407,11 @@ PART 4: COMMANDS $ hledger test -- -pData.Amount --color=never - For help on these, see https://github.com/feuerbach/tasty#options (-- + For help on these, see https://github.com/feuerbach/tasty#options (-- --help currently doesn't show them). PART 5: COMMON TASKS - Here are some quick examples of how to do some basic tasks with + Here are some quick examples of how to do some basic tasks with hledger. Getting help @@ -8303,37 +8421,37 @@ PART 5: COMMON TASKS $ hledger --help # show common options $ hledger CMD --help # show CMD's options, common options and CMD's documentation - You can also view your hledger version's manual in several formats by + You can also view your hledger version's manual in several formats by using the help command. Eg: $ hledger help # show the hledger manual with info, man or $PAGER (best available) $ hledger help journal # show the journal topic in the hledger manual $ hledger help --help # find out more about the help command - To view manuals and introductory docs on the web, visit - https://hledger.org. Chat and mail list support and discussion + To view manuals and introductory docs on the web, visit + https://hledger.org. Chat and mail list support and discussion archives can be found at https://hledger.org/support. Constructing command lines - hledger has a flexible command line interface. We strive to keep it - simple and ergonomic, but if you run into one of the sharp edges de- + hledger has a flexible command line interface. We strive to keep it + simple and ergonomic, but if you run into one of the sharp edges de- scribed in OPTIONS, here are some tips that might help: - o command-specific options must go after the command (it's fine to put + o command-specific options must go after the command (it's fine to put common options there too: hledger CMD OPTS ARGS) - o running add-on executables directly simplifies command line parsing + o running add-on executables directly simplifies command line parsing (hledger-ui OPTS ARGS) o enclose "problematic" args in single quotes - o if needed, also add a backslash to hide regular expression metachar- + o if needed, also add a backslash to hide regular expression metachar- acters from the shell o to see how a misbehaving command line is being parsed, add --debug=2. Starting a journal file - hledger looks for your accounting data in a journal file, + hledger looks for your accounting data in a journal file, $HOME/.hledger.journal by default: $ hledger stats @@ -8341,9 +8459,9 @@ PART 5: COMMON TASKS Please create it first, eg with "hledger add" or a text editor. Or, specify an existing journal file with -f or LEDGER_FILE. - You can override this by setting the LEDGER_FILE environment variable - (see below). It's a good practice to keep this important file under - version control, and to start a new file each year. So you could do + You can override this by setting the LEDGER_FILE environment variable + (see below). It's a good practice to keep this important file under + version control, and to start a new file each year. So you could do something like this: $ mkdir ~/finance @@ -8369,28 +8487,28 @@ PART 5: COMMON TASKS Setting LEDGER_FILE How to set LEDGER_FILE permanently depends on your setup: - On unix and mac, running these commands in the terminal will work for + On unix and mac, running these commands in the terminal will work for many people; adapt as needed: - $ echo 'export LEDGER_FILE=~/finance/2023.journal` >> ~/.profile + $ echo 'export LEDGER_FILE=~/finance/2023.journal' >> ~/.profile $ source ~/.profile - When correctly configured, in a new terminal window env | grep + When correctly configured, in a new terminal window env | grep LEDGER_FILE will show your file, and so will hledger files. - On mac, this additional step might be helpful for GUI applications - (like Emacs started from the dock): add an entry to ~/.MacOSX/environ- + On mac, this additional step might be helpful for GUI applications + (like Emacs started from the dock): add an entry to ~/.MacOSX/environ- ment.plist like { "LEDGER_FILE" : "~/finance/2023.journal" } - and then run killall Dock in a terminal window (or restart the ma- + and then run killall Dock in a terminal window (or restart the ma- chine). On Windows, see https://www.java.com/en/download/help/path.html, or try - running these commands in a powershell window (let us know if it per- + running these commands in a powershell window (let us know if it per- sists across a reboot, and if you need to be an Administrator): > CD @@ -8398,20 +8516,20 @@ PART 5: COMMON TASKS > SETX LEDGER_FILE "C:\Users\USERNAME\finance\2023.journal" Setting opening balances - Pick a starting date for which you can look up the balances of some - real-world assets (bank accounts, wallet..) and liabilities (credit + Pick a starting date for which you can look up the balances of some + real-world assets (bank accounts, wallet..) and liabilities (credit cards..). - To avoid a lot of data entry, you may want to start with just one or + To avoid a lot of data entry, you may want to start with just one or two accounts, like your checking account or cash wallet; and pick a re- - cent starting date, like today or the start of the week. You can al- - ways come back later and add more accounts and older transactions, eg + cent starting date, like today or the start of the week. You can al- + ways come back later and add more accounts and older transactions, eg going back to january 1st. - Add an opening balances transaction to the journal, declaring the bal- + Add an opening balances transaction to the journal, declaring the bal- ances on this date. Here are two ways to do it: - o The first way: open the journal in any text editor and save an entry + o The first way: open the journal in any text editor and save an entry like this: 2023-01-01 * opening balances @@ -8421,19 +8539,19 @@ PART 5: COMMON TASKS liabilities:creditcard $-50 = $-50 equity:opening/closing balances - These are start-of-day balances, ie whatever was in the account at + These are start-of-day balances, ie whatever was in the account at the end of the previous day. - The * after the date is an optional status flag. Here it means + The * after the date is an optional status flag. Here it means "cleared & confirmed". - The currency symbols are optional, but usually a good idea as you'll + The currency symbols are optional, but usually a good idea as you'll be dealing with multiple currencies sooner or later. - The = amounts are optional balance assertions, providing extra error + The = amounts are optional balance assertions, providing extra error checking. - o The second way: run hledger add and follow the prompts to record a + o The second way: run hledger add and follow the prompts to record a similar transaction: $ hledger add @@ -8470,18 +8588,18 @@ PART 5: COMMON TASKS Starting the next transaction (. or ctrl-D/ctrl-C to quit) Date [2023-01-01]: . - If you're using version control, this could be a good time to commit + If you're using version control, this could be a good time to commit the journal. Eg: $ git commit -m 'initial balances' 2023.journal Recording transactions - As you spend or receive money, you can record these transactions using - one of the methods above (text editor, hledger add) or by using the - hledger-iadd or hledger-web add-ons, or by using the import command to + As you spend or receive money, you can record these transactions using + one of the methods above (text editor, hledger add) or by using the + hledger-iadd or hledger-web add-ons, or by using the import command to convert CSV data downloaded from your bank. - Here are some simple transactions, see the hledger_journal(5) manual + Here are some simple transactions, see the hledger_journal(5) manual and hledger.org for more ideas: 2023/1/10 * gift received @@ -8497,22 +8615,22 @@ PART 5: COMMON TASKS assets:bank:checking $1000 Reconciling - Periodically you should reconcile - compare your hledger-reported bal- - ances against external sources of truth, like bank statements or your - bank's website - to be sure that your ledger accurately represents the - real-world balances (and, that the real-world institutions have not - made a mistake!). This gets easy and fast with (1) practice and (2) - frequency. If you do it daily, it can take 2-10 minutes. If you let - it pile up, expect it to take longer as you hunt down errors and dis- + Periodically you should reconcile - compare your hledger-reported bal- + ances against external sources of truth, like bank statements or your + bank's website - to be sure that your ledger accurately represents the + real-world balances (and, that the real-world institutions have not + made a mistake!). This gets easy and fast with (1) practice and (2) + frequency. If you do it daily, it can take 2-10 minutes. If you let + it pile up, expect it to take longer as you hunt down errors and dis- crepancies. A typical workflow: - 1. Reconcile cash. Count what's in your wallet. Compare with what - hledger reports (hledger bal cash). If they are different, try to - remember the missing transaction, or look for the error in the al- - ready-recorded transactions. A register report can be helpful - (hledger reg cash). If you can't find the error, add an adjustment + 1. Reconcile cash. Count what's in your wallet. Compare with what + hledger reports (hledger bal cash). If they are different, try to + remember the missing transaction, or look for the error in the al- + ready-recorded transactions. A register report can be helpful + (hledger reg cash). If you can't find the error, add an adjustment transaction. Eg if you have $105 after the above, and can't explain the missing $2, it could be: @@ -8522,26 +8640,26 @@ PART 5: COMMON TASKS 2. Reconcile checking. Log in to your bank's website. Compare today's (cleared) balance with hledger's cleared balance (hledger bal check- - ing -C). If they are different, track down the error or record the - missing transaction(s) or add an adjustment transaction, similar to + ing -C). If they are different, track down the error or record the + missing transaction(s) or add an adjustment transaction, similar to the above. Unlike the cash case, you can usually compare the trans- - action history and running balance from your bank with the one re- - ported by hledger reg checking -C. This will be easier if you gen- - erally record transaction dates quite similar to your bank's clear- + action history and running balance from your bank with the one re- + ported by hledger reg checking -C. This will be easier if you gen- + erally record transaction dates quite similar to your bank's clear- ing dates. 3. Repeat for other asset/liability accounts. - Tip: instead of the register command, use hledger-ui to see a live-up- + Tip: instead of the register command, use hledger-ui to see a live-up- dating register while you edit the journal: hledger-ui --watch --regis- ter checking -C - After reconciling, it could be a good time to mark the reconciled - transactions' status as "cleared and confirmed", if you want to track - that, by adding the * marker. Eg in the paycheck transaction above, + After reconciling, it could be a good time to mark the reconciled + transactions' status as "cleared and confirmed", if you want to track + that, by adding the * marker. Eg in the paycheck transaction above, insert * between 2023-01-15 and paycheck - If you're using version control, this can be another good time to com- + If you're using version control, this can be another good time to com- mit: $ git commit -m 'txns' 2023.journal @@ -8613,7 +8731,7 @@ PART 5: COMMON TASKS -------------------- 0 - Show only asset and liability balances, as a flat list, limited to + Show only asset and liability balances, as a flat list, limited to depth 2: $ hledger bal assets liabilities -2 @@ -8623,7 +8741,7 @@ PART 5: COMMON TASKS -------------------- $4055 - Show the same thing without negative numbers, formatted as a simple + Show the same thing without negative numbers, formatted as a simple balance sheet: $ hledger bs -2 @@ -8690,77 +8808,83 @@ PART 5: COMMON TASKS 2023-01-13 **** Migrating to a new file - At the end of the year, you may want to continue your journal in a new + At the end of the year, you may want to continue your journal in a new file, so that old transactions don't slow down or clutter your reports, - and to help ensure the integrity of your accounting history. See the + and to help ensure the integrity of your accounting history. See the close command. If using version control, don't forget to git add the new file. BUGS We welcome bug reports in the hledger issue tracker (shortcut: - http://bugs.hledger.org), or on the #hledger chat or hledger mail list + http://bugs.hledger.org), or on the #hledger chat or hledger mail list (https://hledger.org/support). Some known issues and limitations: - The need to precede add-on command options with -- when invoked from + The need to precede add-on command options with -- when invoked from hledger is awkward. (See Command options, Constructing command lines.) - A UTF-8-aware system locale must be configured to work with non-ascii + A UTF-8-aware system locale must be configured to work with non-ascii data. (See Unicode characters, Troubleshooting.) On Microsoft Windows, depending whether you are running in a CMD window or a Cygwin/MSYS/Mintty window and how you installed hledger, non-ascii characters and colours may not be supported, and the tab key may not be - supported by hledger add. (Running in a WSL window should resolve + supported by hledger add. (Running in a WSL window should resolve these.) When processing large data files, hledger uses more memory than Ledger. Troubleshooting - Here are some common issues you might encounter when you run hledger, - and how to resolve them (and remember also you can usually get quick + Here are some common issues you might encounter when you run hledger, + and how to resolve them (and remember also you can usually get quick Support): PATH issues: I get an error like "No command 'hledger' found" Depending how you installed hledger, the executables may not be in your - shell's PATH. Eg on unix systems, stack installs hledger in ~/.lo- + shell's PATH. Eg on unix systems, stack installs hledger in ~/.lo- cal/bin and cabal installs it in ~/.cabal/bin. You may need to add one - of these directories to your shell's PATH, and/or open a new terminal + of these directories to your shell's PATH, and/or open a new terminal window. - LEDGER_FILE issues: I configured LEDGER_FILE but hledger is not using + LEDGER_FILE issues: I configured LEDGER_FILE but hledger is not using it - o LEDGER_FILE should be a real environment variable, not just a shell + o LEDGER_FILE should be a real environment variable, not just a shell variable. Eg on unix, the command env | grep LEDGER_FILE should show - it. You may need to use export (see https://stackover- + it. You may need to use export (see https://stackover- flow.com/a/7411509). - o You may need to force your shell to see the new configuration. A + o You may need to force your shell to see the new configuration. A simple way is to close your terminal window and open a new one. - LANG issues: I get errors like "Illegal byte sequence" or "Invalid or + LANG issues: I get errors like "Illegal byte sequence" or "Invalid or incomplete multibyte or wide character" or "commitAndReleaseBuffer: in- valid argument (invalid character)" - Programs compiled with GHC (hledger, haskell build tools, etc.) need - the system locale to be UTF-8-aware, or they will fail when they en- - counter non-ascii characters. To fix it, set the LANG environment - variable to a locale which supports UTF-8 and which is installed on + Programs compiled with GHC (hledger, haskell build tools, etc.) need + the system locale to be UTF-8-aware, or they will fail when they en- + counter non-ascii characters. To fix it, set the LANG environment + variable to a locale which supports UTF-8 and which is installed on your system. - On unix, locale -a lists the installed locales. Look for one which - mentions utf8, UTF-8 or similar. Some examples: C.UTF-8, en_US.utf-8, - fr_FR.utf8. If necessary, use your system package manager to install - one. Then select it by setting the LANG environment variable. Note, - exact spelling and capitalisation of the locale name may be important: + On unix, locale -a lists the installed locales. Look for one which + mentions utf8, UTF-8 or similar. Some examples: C.UTF-8, en_US.utf-8, + fr_FR.utf8. If necessary, use your system package manager to install + one. Then select it by setting the LANG environment variable. Note, + exact spelling and capitalisation of the locale name may be important: Here's one common way to configure this permanently for your shell: $ echo "export LANG=en_US.utf8" >>~/.profile # close and re-open terminal window + If you are using Nix (not NixOS) for GHC and Hledger, you might need to + set the LOCALE_ARCHIVE variable: + + $ echo "export LOCALE_ARCHIVE=${glibcLocales}/lib/locale/locale-archive" >>~/.profile + # close and re-open terminal window + COMPATIBILITY ISSUES: hledger gives an error with my Ledger file - Not all of Ledger's journal file syntax or feature set is supported. + Not all of Ledger's journal file syntax or feature set is supported. See hledger and Ledger for full details. @@ -8781,4 +8905,4 @@ LICENSE SEE ALSO hledger(1), hledger-ui(1), hledger-web(1), ledger(1) -hledger-1.31.99 September 2023 HLEDGER(1) +hledger-1.31.99 November 2023 HLEDGER(1)