mlr(1)
Miller is a command-line tool for querying, transforming, and reformatting data in CSV, JSON, TSV, and other formats.
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
| Flag | What it does |
|---|---|
-I | In-place processing; modifies files directly instead of writing to stdout |
--csv | Use CSV format for both input and output (default if not specified) |
--json | Use JSON format for both input and output |
--tsv | Use tab-separated values format |
--ifs | Set input field separator (e.g., --ifs=':' for colon-delimited) |
--ofs | Set output field separator (e.g., --ofs='|' for pipe-delimited) |
--rs | Set record separator (line terminator) for input |
--from | Specify input file format (csv, json, tsv, etc.) |
--to | Specify output file format (csv, json, tsv, etc.) |
-n | Use implicit streaming; don't load entire file into memory |
--barred | Use XTAB (key-value pair) format with ASCII bars for readability |
-v | Set 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.csvSelect only 'name' and 'age' columns from CSV file
mlr --csv cut -f name,age data.csvShow only rows where age is greater than 25
mlr --csv filter '$age > 25' data.csvCalculate sum and mean of salary grouped by department
mlr --csv stats1 -a sum,mean -f salary -g department data.csvConvert CSV file to JSON format
mlr --csv --to json data.csvConvert JSON file to CSV format
mlr --json --to csv data.jsonSort records by last_name then first_name
mlr --csv sort -f last_name,first_name data.csvCreate a new derived column by concatenating existing fields
mlr --csv put '$full_name = $first_name . " " . $last_name' data.csv