$linuxjunkies
>

mlr(1)

Miller is a command-line tool for querying, transforming, and reformatting data in CSV, JSON, TSV, and other formats.

UbuntuDebianFedoraArch

Synopsis

mlr [GLOBAL OPTIONS] VERB [VERB OPTIONS] [FILE]...

Description

Miller (mlr) is a data transformation and analysis tool that works on structured text data (CSV, JSON, TSV, NDJSON, etc.). It combines the best features of Unix text processing tools like awk, sed, and cut with a modern, readable syntax for filtering, reshaping, and computing on tabular data.

Use mlr to slice, reshape, aggregate, and reformat data on the command line without writing scripts. It handles multiple input/output formats, preserves field order, and supports complex operations like joins, grouping, and statistics.

Common options

FlagWhat it does
-IIn-place processing; modifies files directly instead of writing to stdout
--csvUse CSV format for both input and output (default if not specified)
--jsonUse JSON format for both input and output
--tsvUse tab-separated values format
--ifsSet input field separator (e.g., --ifs=':' for colon-delimited)
--ofsSet output field separator (e.g., --ofs='|' for pipe-delimited)
--rsSet record separator (line terminator) for input
--fromSpecify input file format (csv, json, tsv, etc.)
--toSpecify output file format (csv, json, tsv, etc.)
-nUse implicit streaming; don't load entire file into memory
--barredUse XTAB (key-value pair) format with ASCII bars for readability
-vSet variable values using key=value pairs (e.g., -v OFS='\t')

Examples

Display CSV file as-is; useful for format validation

mlr --csv cat data.csv

Select only 'name' and 'age' columns from CSV file

mlr --csv cut -f name,age data.csv

Show only rows where age is greater than 25

mlr --csv filter '$age > 25' data.csv

Calculate sum and mean of salary grouped by department

mlr --csv stats1 -a sum,mean -f salary -g department data.csv

Convert CSV file to JSON format

mlr --csv --to json data.csv

Convert JSON file to CSV format

mlr --json --to csv data.json

Sort records by last_name then first_name

mlr --csv sort -f last_name,first_name data.csv

Create a new derived column by concatenating existing fields

mlr --csv put '$full_name = $first_name . " " . $last_name' data.csv

Related commands