any script to order transactions by date

68 views
Skip to first unread message

Christian Pinedo Zamalloa

unread,
Dec 6, 2019, 6:19:16 AM12/6/19
to ledge...@googlegroups.com
Hi!
I would like to know if you have any shell, awk... script to sort the
order of ledger transactions by date.

Initially I tried to sort transactions per date by using "ledger
print", however I suffered some issues with the output generated by
"ledger print" command:
- some lot data disappears
- lot dates are translated to a format not valid (it seems to be
solved in this commit
https://github.com/ledger/ledger/commit/95237941b66931978953fadb390e1b442ed63175
)

I am a vim user, so I don't use the emacs' mode for ledger.

Regards!

--
Christian Pinedo Zamalloa (zako)
PGP keyID: 0xdb577d4ee6ffbd55
PGP Fgprt: A895 7C11 84F6 30B4 4938 32A4 9306 DFD0 CDE4 B542

Scott Carpenter

unread,
Dec 6, 2019, 12:57:27 PM12/6/19
to Ledger
Ledgerbil has a sorting feature:


The only change it will make to data is to normalize spacing between transactions, using one space.

Ledgerbil doesn't know about a lot of ledger features but it should still be able to sort any file. Please let me know if any issues and I'll be happy to attempt a fix!
Message has been deleted

maktak

unread,
Dec 6, 2019, 1:36:51 PM12/6/19
to Ledger
I had some similar issues using the ledger print command. It discards some data such as comments outside of transactions as well as balance assertions. To solve this problem, I wrote a script in Python to sort transactions by date without touching the formatting or data. If you think Python could work for you, let me know and I'll try to upload it to Github.

Martin Michlmayr

unread,
Dec 7, 2019, 3:38:35 AM12/7/19
to ledge...@googlegroups.com
* maktak <mak...@gmail.com> [2019-12-06 10:34]:
> I had some similar issues using the ledger print command. It
> discards some data such as comments outside of transactions as well
> as balance assertions. To solve this problem, I wrote a script in
> Python to sort transactions by data without touching the formatting
> or data. If you think Python could work for you, let me know and
> I'll try to upload it to Github.

I'm not the person who asked for this, but I would be interested for sure.

--
Martin Michlmayr
https://www.cyrius.com/

Christian Pinedo Zamalloa

unread,
Dec 7, 2019, 3:45:56 AM12/7/19
to ledge...@googlegroups.com
Hi maktak!

it would be great if you could share your script. It suits better with my way of completing ledger-cli with small scripts.

I will check also ledgerbli!

Thanks,

--
Christian Pinedo Zamalloa (zako)
Sent from my mobile device, please excuse brevity or typos

--

---
You received this message because you are subscribed to the Google Groups "Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ledger-cli+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ledger-cli/6fa2e284-8ede-41ca-b51e-aaad0126d0f9%40googlegroups.com.

John Wiegley

unread,
Dec 9, 2019, 4:08:00 AM12/9/19
to maktak, Ledger
>>>>> "m" == maktak <mak...@gmail.com> writes:

m> I had some similar issues using the ledger print command. It discards some
m> data such as comments outside of transactions as well as balance
m> assertions. To solve this problem, I wrote a script in Python to sort
m> transactions by data without touching the formatting or data. If you think
m> Python could work for you, let me know and I'll try to upload it to Github.

Did you try `ledger print --raw`? That should preserve all information about
the transaction, including whatever was in the original file, exactly as you
had written there.

John

maktak

unread,
Dec 9, 2019, 4:20:14 PM12/9/19
to Ledger
On Monday, December 9, 2019 at 4:08:00 AM UTC-5, John Wiegley wrote:

Did you try `ledger print --raw`? That should preserve all information about
the transaction, including whatever was in the original file, exactly as you
had written there.

John

Yes, I tried that command but it has 2 undesirable outcomes:

1) It strips any comments in the file that are between 2 transactions. Only comments inside a transaction are preserved. I like to insert block-style comments between transactions for documentary and journaling purposes.

2) It strips net zero transactions, such as the following:

2019/01/01 Acme Bank
Assets:Bank:Acme  EUR  0 = EUR 688.68

I sometimes use single line, net zero transactions to make balance assertions and reconcile accounts against statements. This is also part of my journaling process where I am testing that all transactions for an account up to that date are present and the balance is correct.

Maybe this usage is unexpected or illegal but it works to do balance assertions. However, the  `ledger print --raw` command strips these single-line balance assertion transactions from the output, probably because the transaction is net zero.

BTW, I love Ledger. It has truly transformed my life, so thanks so much for creating it!!

M.

Jostein Berntsen

unread,
Dec 10, 2019, 6:05:38 PM12/10/19
to ledge...@googlegroups.com
On 06.12.19,12:19, Christian Pinedo Zamalloa wrote:
> Hi!
> I would like to know if you have any shell, awk... script to sort the
> order of ledger transactions by date.
>
> Initially I tried to sort transactions per date by using "ledger
> print", however I suffered some issues with the output generated by
> "ledger print" command:
> - some lot data disappears
> - lot dates are translated to a format not valid (it seems to be
> solved in this commit
> https://github.com/ledger/ledger/commit/95237941b66931978953fadb390e1b442ed63175
> )
>
> I am a vim user, so I don't use the emacs' mode for ledger.
>

I have made a perl script last year which has an option to sort the
transaction file by dates without changing it and one for changing the
file. I will see if I can upload this to github if this is useful.

Jostein

Reply all
Reply to author
Forward
0 new messages