hledger
hledger copied to clipboard
CSV import, comments
I miss a directive to create a comment for CSV import. These could be useful for debugging or storing extra information to the journal. Comment statement could be used several times to have multi line comment. With comment I would see source data from CSV (as a comment) and how those data were translated to hledger journal. Great for bug reports... ;-)
An extra field %0 could be added, this filed will expand to the input line ($0 is input line in awk). Example usage comment %0
UPDATE: I just found that hledger supports comments with comment or commentX, where X is a number. These are appended after ledger entry.
What about comment0 that will store comment before ledger entry, like comment0 %0, to store CSV line before ledger entry...
Other usage, to store entry separator, like comment0 ##########
Example,
$ cat demo-ireland4.csv
Date, Description, Id, Amount, Currency
12/11/2019, Foo, 123, 10.23, EUR
$ cat demo-ireland4.csv.rules
# basic.csv.rules
skip 1
date-format %d/%m/%Y
#separator ,
fields date, description, _, _amount, _currency
#currency EUR
#date %1
#description
amount %_amount %_currency
comment %1,%2,%3,%4,%5
comment1 remark line 1
comment2 remark line 2 # this comment is stored!
comment3 remark line 3 # no line 3, comment is lost...
#comment0 %0\n
$ ./hledger -f demo-ireland4.csv print
2019-11-12 Foo ; 12/11/2019,Foo,123,10.23,EUR
expenses:unknown 10.23 EUR ; remark line 1
income:unknown -10.23 EUR ; remark line 2 # this comment is stored!
comment0 %0\n should print this:
; 12/11/2019, Foo, 123, 10.23, EUR
2019-11-12 Foo
expenses:unknown 10.23 EUR
income:unknown -10.23 EUR
Observation:
random ':' in input CSV file can create random tags. Command hledger tags doesn't print any tags when it reads directly CSV file but once data are stored in journal format (with comments from CSV, defined in rules file), hledger tags reports many tags. For example, ; 17144964,2021-12-11 10:22:10,BTC,Credit,0.00001510,order: 1234 will create several tags from timestamp (field %2), tags like 10, 22, 10 and even BTC,Credit,0.00001510,order...
When comment starts with #, tags are not created. I just don't know how to create comment that starts with '#'. comment in csv.rules file create comments those start with ;.
I want to create something like this, I do not want hledger to search comment in sample of CSV record. It is not perfect because when file decription has random :, random tag will be created...
# 12/11/2019 09:25:59, Payment: SmartMobiles | order: 123432, 123, 10.23, EUR
2019-11-12 Payment: SmartMobiles | order: 123432
expenses:unknown 10.23 EUR
income:unknown -10.23 EUR
When I started with hledger, I start to write my own parser in awk to read CSV data. Then I discovered CSV import rules in hledger and I try to use them. It looked like a great idea but they have so many limitations, I think that I should return to awk parser, it has greater control how to create output journal... :-(