;scripts: hledgerj1: example of a wrapper reading a custom format
This commit is contained in:
parent
508f011b1d
commit
17508cc844
@ -406,6 +406,23 @@ $ hledger timedothm sample.timedothm reg -w80
|
|||||||
(time) 0:30 2:00
|
(time) 0:30 2:00
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### hledgerj1
|
||||||
|
|
||||||
|
[`hledgerj1`](https://github.com/simonmichael/hledger/blob/master/bin/hledgerj1)
|
||||||
|
is a small example of a wrapper script that preprocesses the journal,
|
||||||
|
converting it from a custom format, in this case a one-line journal format
|
||||||
|
where slash represents newline. Eg:
|
||||||
|
```text
|
||||||
|
2025-01-04 shopping / assets:bank:checking / expenses:food 200 USD / expenses:supplies 50 USD
|
||||||
|
```
|
||||||
|
```cli
|
||||||
|
$ hledgerj1 a.j1 print
|
||||||
|
2025-01-04 shopping
|
||||||
|
assets:bank:checking
|
||||||
|
expenses:food 200 USD
|
||||||
|
expenses:supplies 50 USD
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## hledger haskell scripts
|
## hledger haskell scripts
|
||||||
|
|
||||||
|
|||||||
46
bin/hledgerj1
Executable file
46
bin/hledgerj1
Executable file
@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# hledgerj1 FILE.j1 HLEDGERARGS..
|
||||||
|
# Convert a one-line journal file (where forward slash is equivalent to newline)
|
||||||
|
# to a standard journal before running hledger on it.
|
||||||
|
# (Does not convert included files, does not work if your journal already contains forward slashes.)
|
||||||
|
|
||||||
|
F=$1; shift
|
||||||
|
|
||||||
|
sed -E -e 's/\//\n /g' <"$F" \
|
||||||
|
| hledger -f- "$@"
|
||||||
|
|
||||||
|
|
||||||
|
# Eg:
|
||||||
|
#
|
||||||
|
# ; sample2.j1
|
||||||
|
# 2025-01-01 starting balances / assets:cash 100 USD = 100 USD / assets:bank:checking 1000 USD = 1000 USD / assets:broker:usd 1000 USD = 1000 USD / assets:broker:aaa 1 AAA @ 1.20 USD = 1 AAA @ 1.20 USD / liabilities:credit card -400 USD = -400 USD / equity:start
|
||||||
|
# 2025-01-01 pay rent / assets:bank:checking / expenses:rent 800 USD
|
||||||
|
# 2025-01-02 salary / revenues:salary / assets:bank:checking 1000 USD
|
||||||
|
# 2025-01-03 pay half of credit card balance / assets:bank:checking / liabilities:credit card 200 USD = -200 USD
|
||||||
|
# 2025-01-04 shopping / assets:bank:checking / expenses:food 200 USD / expenses:supplies 50 USD
|
||||||
|
#
|
||||||
|
# $ hledgerj1 examples/sample2.j1 print
|
||||||
|
# 2025-01-01 starting balances
|
||||||
|
# assets:cash 100 USD = 100 USD
|
||||||
|
# assets:bank:checking 1000 USD = 1000 USD
|
||||||
|
# assets:broker:usd 1000 USD = 1000 USD
|
||||||
|
# assets:broker:aaa 1 AAA @ 1.20 USD = 1 AAA @ 1.20 USD
|
||||||
|
# liabilities:credit card -400 USD = -400 USD
|
||||||
|
# equity:start
|
||||||
|
#
|
||||||
|
# 2025-01-01 pay rent
|
||||||
|
# assets:bank:checking
|
||||||
|
# expenses:rent 800 USD
|
||||||
|
#
|
||||||
|
# 2025-01-02 salary
|
||||||
|
# revenues:salary
|
||||||
|
# assets:bank:checking 1000 USD
|
||||||
|
#
|
||||||
|
# 2025-01-03 pay half of credit card balance
|
||||||
|
# assets:bank:checking
|
||||||
|
# liabilities:credit card 200 USD = -200 USD
|
||||||
|
#
|
||||||
|
# 2025-01-04 shopping
|
||||||
|
# assets:bank:checking
|
||||||
|
# expenses:food 200 USD
|
||||||
|
# expenses:supplies 50 USD
|
||||||
9
examples/sample.j1
Normal file
9
examples/sample.j1
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# sample1.jnl1
|
||||||
|
# A one-line variant of journal format, where forward slashes are equivalent to newlines.
|
||||||
|
# Read by bin/hledgerj1.
|
||||||
|
|
||||||
|
2025-01-01 starting balances / assets:cash 100 USD = 100 USD / assets:bank:checking 1000 USD = 1000 USD / assets:broker:usd 1000 USD = 1000 USD / assets:broker:aaa 1 AAA @ 1.20 USD = 1 AAA @ 1.20 USD / liabilities:credit card -400 USD = -400 USD / equity:start
|
||||||
|
2025-01-01 pay rent / assets:bank:checking / expenses:rent 800 USD
|
||||||
|
2025-01-02 salary / revenues:salary / assets:bank:checking 1000 USD
|
||||||
|
2025-01-03 pay half of credit card balance / assets:bank:checking / liabilities:credit card 200 USD = -200 USD
|
||||||
|
2025-01-04 shopping / assets:bank:checking / expenses:food 200 USD / expenses:supplies 50 USD
|
||||||
Loading…
Reference in New Issue
Block a user