;doc:csv:source: add data command examples

This commit is contained in:
Simon Michael 2025-08-28 05:18:37 +01:00
parent a5ec1cb888
commit 91b24df4b2

View File

@ -3321,9 +3321,27 @@ If hledger's CSV rules aren't enough, you can pre-process the downloaded data he
The command will be executed by your default shell, in the directory of the rules file, will receive the data file's content as standard input,
and should output zero or more lines of character-separated-values, suitable for conversion by the CSV rules.
Examples:
```
source ./paypal.json | paypalcsv
source data/simplefin.json | simplefincsv - 'chase.*card'
source OfxDownload*.csv | grep -vE '^(([^,]*,){6}[^,]*|)$' | sort -t, -n +2
source History_for_Account_Z20144832*.csv # | grep -E '^([^,]*,){12}[^,]*$' | sed -E -e 's/^ //' -e 's/\.([0-9]),/.\10,/g' -e 's/,([0-9]+),/,\1.00,/g'
```
Or, after `source` you can write `|` and a data generating command (with no file pattern before the `|`).
This command receives no input, and should output zero or more lines of character-separated values, suitable for conversion by the CSV rules.
Examples:
```
source | paypaljson | paypalcsv
source | paypalcsv data/paypal.json
source | simplefinjson >data/simplefin.json && simplefincsv data/simplefin.json 'chase.*card'
source | simplefincsv data/simplefin.json 'unify.*checking'
```
(`paypal*` and `simplefin*` scripts are in [bin/](https://github.com/simonmichael/hledger/tree/master/bin#readme))
Whenever hledger runs one of these commands, it will print the command on stderr.
If the command produces error output, but exits successfully, hledger will show the error output as a warning.
If the command fails, hledger will fail and show the error output in the error message.