LinuxCommandLibrary

miller

TLDR

Convert CSV to JSON

$ mlr --csv --ojson cat [file.csv]
copy
Filter records
$ mlr --csv filter '$[field] > [10]' [file.csv]
copy
Select columns
$ mlr --csv cut -f [name,age] [file.csv]
copy
Sort by field
$ mlr --csv sort -f [age] [file.csv]
copy
Aggregate statistics
$ mlr --csv stats1 -a sum,mean -f [value] -g [category] [file.csv]
copy
Transform field
$ mlr --csv put '$[total] = $[price] * $[quantity]' [file.csv]
copy

SYNOPSIS

mlr [options] verb [verb-options] files...

DESCRIPTION

Miller (mlr) is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and JSON. It's designed for processing structured text data from the command line.
Miller handles heterogeneous data formats with consistent syntax.

PARAMETERS

--csv

CSV input format.
--json
JSON input format.
--ojson
JSON output format.
--icsv --ojson
CSV in, JSON out.
cat
Pass through records.
filter
Select matching records.
cut
Select fields.
sort
Sort records.
put
Add/modify fields.
stats1
Aggregate statistics.

FORMAT CONVERSION

$ mlr --icsv --ojson cat data.csv
mlr --ijson --ocsv cat data.json
mlr --csv --opprint cat data.csv
copy

CAVEATS

DSL syntax differs from awk. Field names are case-sensitive. Large files processed streaming.

HISTORY

Miller was created by John Kerl starting in 2015 to provide a unified tool for structured text processing.

SEE ALSO

jq(1), awk(1), csvkit(1), xsv(1)

Copied to clipboard