tldr/pages/common/mlr.md

33 lines
1.0 KiB
Markdown
Raw Normal View History

2018-10-16 18:26:42 +01:00
# mlr
> Miller is like `awk`, `sed`, `cut`, `join`, and `sort` for name-indexed data such as CSV, TSV, and tabular JSON.
2019-06-04 10:25:13 +01:00
> More information: <https://johnkerl.org/miller/doc>.
2018-10-16 18:26:42 +01:00
- Pretty-print a CSV file in a tabular format:
`mlr --icsv --opprint cat {{example.csv}}`
- Receive JSON data and pretty print the output:
`echo '{"hello":"world"}' | mlr --ijson --opprint cat`
- Sort alphabetically on a field:
`mlr --icsv --opprint sort -f {{field}} {{example.csv}}`
- Sort in descending numerical order on a field:
`mlr --icsv --opprint sort -nr {{field}} {{example.csv}}`
- Convert CSV to JSON, performing calculations and display those calculations:
`mlr --icsv --ojson put '${{newField1}} = ${{oldFieldA}}/${{oldFieldB}}' {{example.csv}}`
- Receive JSON and format the output as vertical JSON:
`echo '{"hello":"world", "foo":"bar"}' | mlr --ijson --ojson --jvstack cat`
2019-11-30 14:17:34 +00:00
- Filter lines of a compressed CSV file treating numbers as strings:
`mlr --prepipe 'gunzip' --csv filter -S '${{fieldName}} =~ "{{regexp}}"' {{example.csv.gz}}`