### Snap-Specific Usage Example
Source: https://deepwiki.com/johnkerl/miller/2.1-installation-guide
After installing via snap, use the executable 'miller' instead of 'mlr'. The 'mlr' command is not available via snap.
```bash
# After snap install:
miller --version # correct
# NOT:
mlr --version # not found via snap
```
--------------------------------
### Configure and install to a custom prefix
Source: https://deepwiki.com/johnkerl/miller/2.2-building-from-source
Run configure with a custom install prefix and then make install to build and install Miller to that location.
```bash
./configure --prefix=/your/install/path
make install
```
--------------------------------
### Example CSV Data File
Source: https://deepwiki.com/johnkerl/miller/2.3-first-steps-with-miller
Example CSV file `example.csv` used in the quick reference examples.
```csv
color,shape,quantity,rate
yellow,triangle,43.6498,9.8870
red,square,79.2778,0.0130
red,circle,13.8103,2.9010
```
--------------------------------
### Install man page to system directory
Source: https://deepwiki.com/johnkerl/miller/8.6-documentation-system
Commands from man/Makefile to install the man page. INSTALLDIR defaults to $(PREFIX)/share/man/man1 and PREFIX defaults to /usr/local.
```makefile
mkdir -p $(DESTDIR)/$(INSTALLDIR)
cp mlr.1 $(DESTDIR)/$(INSTALLDIR)/mlr.1
```
--------------------------------
### REPL :help command
Source: https://deepwiki.com/johnkerl/miller/6.1-repl-commands-and-workflow
Lists all available colon-commands with short descriptions. Use :help examples for extended usage examples.
```text
[mlr] :help
```
--------------------------------
### Verb options placement examples
Source: https://deepwiki.com/johnkerl/miller/3.2-command-line-interface
Shows verb options placed between the verb name and input files, with examples for cut, sort, and stats1.
```bash
# cut verb with -f (fields) option
mlr --csv cut -f name,age data.csv
# sort verb with -f (field) and -nr (numeric reverse) options
mlr --csv sort -f age -nr data.csv
# stats1 verb with -a (aggregations), -f (field), -g (group-by) options
mlr --csv stats1 -a mean,sum -f salary -g department data.csv
```
--------------------------------
### PPRINT example
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Sample PPRINT data with aligned columns. Use with --pprint or --p2p.
```pprint
apple bat cog
1 2 3
4 5 6
```
--------------------------------
### stats1 example with CSV input
Source: https://deepwiki.com/johnkerl/miller/4.3-statistical-verbs
Example command using stats1 with CSV input, computing min, mean, and max on the quantity field, then sorting by color.
```text
mlr --csv stats1 -a min,mean,max -f quantity then sort -f color example.csv
```
--------------------------------
### count and count-distinct examples
Source: https://deepwiki.com/johnkerl/miller/4.3-statistical-verbs
Example commands for counting records grouped by color and counting distinct shapes.
```text
mlr count -g color
mlr count-distinct -f shape
```
--------------------------------
### Install staticcheck
Source: https://deepwiki.com/johnkerl/miller/8.4-testing-framework
Install staticcheck separately since it is not a runtime dependency in go.mod. The tool must be available in $PATH for 'make staticcheck' to work.
```bash
go install honnef.co/go/tools/cmd/staticcheck@latest
```
--------------------------------
### mlr bootstrap example
Source: https://deepwiki.com/johnkerl/miller/4.3-statistical-verbs
Example of using bootstrap followed by stats1 to compute the mean of field x.
```bash
mlr bootstrap then stats1 -a mean -f x
```
--------------------------------
### DCF example
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Sample DCF data with key: value pairs. Use with --dcf.
```dcf
apple: 1
bat: 2
cog: 3
dish: 7
egg: 8
```
--------------------------------
### DKVPX example
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Example of DKVPX, which uses CSV-style quoting. Use with --dkvpx.
```dkvp
"x,y"="a,b,c",z=3
```
--------------------------------
### `rename` basic and regex examples
Source: https://deepwiki.com/johnkerl/miller/4.2-data-transformation-verbs
Examples of the `rename` verb: first renames pairs of fields (old_name to new_name, old2 to new2); second uses `-r` to interpret the pattern as a regular expression and renames fields starting with 'prefix_' to capture the suffix.
```text
mlr rename old_name,new_name,old2,new2
mlr rename -r 'prefix_(.+),\1'
```
--------------------------------
### Compute Percentages Example
Source: https://deepwiki.com/johnkerl/miller/7.1-two-pass-algorithms
Demonstrates tracking min/max values in a first pass and computing percentages in an end block.
```text
Input: x values: 0.204, 0.346, 0.381, 0.573, 0.758
Output: x_pct: 0%, 25.7%, 31.9%, 66.5%, 100%
```
```text
# First pass: track min/max and retain values
@x_min = min($x, @x_min);
@x_max = max($x, @x_max);
@x[NR] = $x;
# Second pass: compute percentages
end {
for (nr, x in @x) {
@x_pct[nr] = 100 * (x - @x_min) / (@x_max - @x_min);
}
emit (@x, @x_pct), "NR"
}
```
--------------------------------
### Build Miller from Git Clone
Source: https://deepwiki.com/johnkerl/miller/2-getting-started
Build and install Miller from a Git clone. Requires Go 1.15 or higher and gcc. The `make` command produces the `./mlr` executable, `make check` runs the test suite, and `sudo make install` installs to `/usr/local` by default.
```bash
git clone https://github.com/johnkerl/miller
cd miller
make # produces ./mlr executable
make check # runs test suite
sudo make install # installs to /usr/local by default
```
--------------------------------
### DKVP example
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Sample DKVP data with key-value pairs separated by commas. Use with --dkvp or --d2d.
```dkvp
apple=1,bat=2,cog=3
dish=7,egg=8,flint
```
--------------------------------
### Miller DSL example: begin/main/end blocks for average
Source: https://deepwiki.com/johnkerl/miller/5.1-dsl-overview-and-execution-model
Example showing initialization in begin, per-record accumulation in the implicit main block, and final emit in end. Uses @total and @count to compute an average.
```dsl
begin {
@total = 0;
@count = 0;
}
# main block (implicit)
@total += $amount;
@count += 1;
end {
emit (@total / @count), "average"
}
```
--------------------------------
### Example CSV with comment line
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Shows a CSV comment line (prefixed with #) followed by data. Comment must be at start of line; by default comments are treated as data.
```text
# This is a comment for a CSV file
a,b,c
1,2,3
4,5,6
```
--------------------------------
### Miller Command Chaining Example
Source: https://deepwiki.com/johnkerl/miller/3-core-concepts
A practical example of chaining the stats1 and sort verbs to process a CSV file.
```bash
mlr --icsv --opprint stats1 -a min,mean,max -f quantity then sort -f color example.csv
```
--------------------------------
### group-by usage examples
Source: https://deepwiki.com/johnkerl/miller/4.4-sorting-and-grouping-verbs
Shows how to group records by one or more fields, and a common pattern of grouping followed by aggregation.
```bash
# Group by single field
mlr --csv group-by color data.csv
# Group by multiple fields
mlr --csv group-by color,shape data.csv
# Common pattern: group then aggregate
mlr --csv group-by color then stats1 -a sum -f quantity data.csv
```
--------------------------------
### Custom prefix installation with configure
Source: https://deepwiki.com/johnkerl/miller/8.2-build-system
Installs Miller to a custom prefix, placing the executable at $HOME/.local/bin/mlr and the man page at $HOME/.local/share/man/man1/mlr.1.
```bash
./configure --prefix=$HOME/.local
make
make install
```
--------------------------------
### Miller verb discovery and help commands
Source: https://deepwiki.com/johnkerl/miller/4.1-verb-overview-and-categories
Commands to list all verbs, show usage for all verbs, get help for a specific verb, and search for verbs by name. Each verb also accepts -h or --help to display its options and usage examples.
```bash
# List all verbs
mlr -l
mlr help list-verbs
# Show usage for all verbs
mlr -L
mlr help usage-verbs
# Get help for a specific verb
mlr {verb} --help
mlr help verb {verb}
# Search for verbs by name
mlr help find sort
```
--------------------------------
### Examples of case-insensitive flag in filter and cut
Source: https://deepwiki.com/johnkerl/miller/5.5-regular-expressions
Help output examples showing the 'i' flag in filter and cut commands.
```text
mlr filter '($name =~ "^sys.*east$") || ($name =~ "^dev.[0-9]+"i)'
mlr cut -r -f '^status$,"sda[0-9]"i'
```
--------------------------------
### Launch Text-Mode pprof for CPU Profile
Source: https://deepwiki.com/johnkerl/miller/7.2-performance-and-profiling
Starts the interactive pprof command-line interface for the CPU profile file `cpu.pprof`, enabling commands like `top10`, `list`, and `web`.
```bash
go tool pprof mlr cpu.pprof
```
--------------------------------
### Miller DSL quick examples: put, filter, and begin/end blocks
Source: https://deepwiki.com/johnkerl/miller/5-domain-specific-language-%28dsl%29
Quick examples of Miller's DSL usage with the put and filter verbs. The first adds a computed field, the second filters records, and the third uses begin/end blocks and an out-of-stream variable.
```bash
# put: add a computed field
mlr --csv put '$ratio = $quantity / $rate' data.csv
# filter: keep only matching records
mlr --csv filter '$color == "red" && $quantity > 10' data.csv
# put with begin/end blocks and out-of-stream variable
mlr --csv put '@total += $quantity; end { emit @total }' data.csv
```
--------------------------------
### Package Manager Installation Commands
Source: https://deepwiki.com/johnkerl/miller/2.1-installation-guide
Commands to install Miller using various package managers. Ensure the package manager is available on your platform. Snap installs the executable as 'miller' instead of 'mlr'.
```bash
yum install miller
```
```bash
apt-get install miller
```
```bash
snap install miller
```
```bash
brew install miller
```
```bash
sudo port selfupdate && sudo port install miller
```
```bash
choco install miller
```
```bash
winget install Miller.Miller
```
```bash
scoop install main/miller
```
```bash
conda install -c conda-forge miller
```
--------------------------------
### Start Miller REPL with 'mlr repl'
Source: https://deepwiki.com/johnkerl/miller/6-interactive-repl
Command to start the Miller REPL. Presents the '[mlr]' prompt and accepts DSL expressions and meta-commands prefixed with ':'.
```bash
mlr repl
```
--------------------------------
### `cut` selection and exclusion examples
Source: https://deepwiki.com/johnkerl/miller/4.2-data-transformation-verbs
Examples of the `cut` verb for selecting fields (`-f`) with optional exclusion (`-x`) and regular expression matching (`-r`). The first command includes the fields hostname and status; the second excludes them; the third uses regex to match fields starting with 'status' or matching 'sda0-9'.
```text
mlr cut -f hostname,status
mlr cut -x -f hostname,status
mlr cut -r -f '^status$,sda[0-9]'
```
--------------------------------
### YAML example
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Sample YAML with two documents separated by ---. Use with --yaml or --y2y.
```yaml
apple: 1
bat: 2
cog: 3
---
dish: 7
egg: 8
```
--------------------------------
### DSL syntax examples from concepts table
Source: https://deepwiki.com/johnkerl/miller/3-core-concepts
Table of key DSL concepts with syntax examples: field reference, all fields, out-of-stream variable, local variable, built-in function, user-defined function, control flow, and output. These are short inline code examples.
```text
$fieldname
```
```text
$*
```
```text
@varname
```
```text
var x = ...
```
```text
strlen($s), gsub($s, ...)
```
```text
func f(x) { return x*2 }
```
```text
if, for, while, do-while
```
```text
emit, tee, dump, print
```
--------------------------------
### mlr bar example
Source: https://deepwiki.com/johnkerl/miller/4.3-statistical-verbs
Example of using bar with --auto limits, fields x and y, width 20, on the data/small file.
```bash
mlr --opprint bar --auto -f x,y -w 20 data/small
```
--------------------------------
### gsub backreference swap example
Source: https://deepwiki.com/johnkerl/miller/5.5-regular-expressions
Example for gsub using backreferences to swap a word and a number separated by underscore.
```plaintext
gsub($name, "^([a-z]+)_([0-9]+)$", "\2_\1")
```
--------------------------------
### Build and test Miller with Go commands
Source: https://deepwiki.com/johnkerl/miller/2.2-building-from-source
Direct Go commands to build, test, run regression tests, and install Miller without using make. The go install variant fetches the latest release from the module proxy without requiring a local clone.
```bash
go build github.com/johnkerl/miller/v6/cmd/mlr
```
```bash
go test github.com/johnkerl/miller/v6/pkg/...
```
```bash
mlr regtest
```
```bash
go install github.com/johnkerl/miller/v6/cmd/mlr@latest
```
--------------------------------
### Main block example: calculating totals and running sum
Source: https://deepwiki.com/johnkerl/miller/5.1-dsl-overview-and-execution-model
This script forms the main block, executed once per input record. It calculates $total and $discounted for each record and accumulates @running_sum across all records.
```dsl
# This entire script is the "main block"
$total = $quantity * $price;
$discounted = $total * 0.9;
@running_sum += $total
```
--------------------------------
### CSV example
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Sample CSV data with a header line and two data rows. Use with --csv or -c for input and output.
```csv
apple,bat,cog
1,2,3
4,5,6
```
--------------------------------
### Run configure with custom prefix
Source: https://deepwiki.com/johnkerl/miller/8.2-build-system
Use this command to configure the build with a custom installation prefix. The configure script accepts `--prefix=/path`, `--prefix /path`, `-p=/path`, and `-p /path` formats and modifies `PREFIX=` lines in `Makefile` and `man/Makefile`. The default prefix is `/usr/local` and the prefix directory must exist and be readable.
```shell
./configure --prefix=/custom/path
```
--------------------------------
### XTAB example
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Sample XTAB data with vertical field layout. Use with --xtab or --x2x.
```xtab
apple 1
bat 2
cog 3
dish 7
egg 8
```
--------------------------------
### Markdown example
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Sample Markdown table. Use with --imd/--imarkdown for input and --omd/--omarkdown for output.
```markdown
| apple | bat | cog |
| --- | --- | --- |
| 1 | 2 | 3 |
| 4 | 5 | 6 |
```
--------------------------------
### Block Structure and Scoping Example
Source: https://deepwiki.com/johnkerl/miller/5.3-variables-and-scoping
Illustrates variable visibility and access constraints across begin, main, and end blocks in Miller.
```Miller
begin {
# Can access: @oosvars, local vars, ENV
# Cannot access: $fields (no records yet)
@sum = 0;
var setup_var = "initialized";
}
# Main block (implicit loop over records)
{
# Can access: $fields, @oosvars, local vars, ENV
@sum += $x;
var record_var = $x * 2;
if ($x > 10) {
var conditional_var = $x - 10;
# Can access: $fields, @oosvars, record_var, conditional_var, ENV
}
# conditional_var not visible here
}
end {
# Can access: @oosvars, local vars, ENV
# Cannot access: $fields (records already processed)
emit @sum;
}
```
--------------------------------
### Explicit Type Conversion Example
Source: https://deepwiki.com/johnkerl/miller/5.2-data-types%3A-strings-and-arrays
Demonstrates explicit conversion using int() and string() functions to convert fields.
```dsl
$int_value = int($string_field)
$string_value = string($numeric_field)
```
--------------------------------
### mlr stats2 CSV example with corr, linreg-ols, r2
Source: https://deepwiki.com/johnkerl/miller/4.3-statistical-verbs
Example command computing correlation, linear regression (OLS), and R-squared on fields x and y, grouped by the color field, from CSV input.
```bash
mlr --csv stats2 -a corr,linreg-ols,r2 -f x,y -g color
```
--------------------------------
### Record templating example
Source: https://deepwiki.com/johnkerl/miller/5.8-output-statements
Example of record templating that replaces every field in the record with the fields defined in the map. Fields not listed are dropped. The output record participates in downstream then-chaining.
```text
$* = {
"color_shape": $color . " " . $shape,
"flags": {
"iflag": $flag == 1,
"w_exceeded": $w > 0.5,
},
"uvwx": [$u, $v, $w, $x],
}
```
--------------------------------
### Per-Group Record Count Example
Source: https://deepwiki.com/johnkerl/miller/7.1-two-pass-algorithms
Shows how to accumulate counts per category and emit records with their associated group totals.
```text
# Accumulate counts
@count_by_group[$category] += 1;
@records[NR] = $*;
# Emit with counts
end {
for (nr, record in @records) {
record["group_count"] = @count_by_group[record["category"]];
emit record
}
}
```
--------------------------------
### NIDX example
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Sample NIDX data with whitespace-separated fields. Use with --nidx or --n2n.
```nidx
the quick brown
fox jumped
```
--------------------------------
### Check Miller version with mlr --version
Source: https://deepwiki.com/johnkerl/miller/2.3-first-steps-with-miller
Run this command to verify that Miller is installed and accessible in your system path. It prints the installed Miller version.
```bash
mlr --version
```
--------------------------------
### Streaming DSL Pattern: Per-record computation with put and filter
Source: https://deepwiki.com/johnkerl/miller/7.3-streaming-and-memory-considerations
Use these commands for per-record computation that maintains O(1) memory. The put example calculates a profit field, and the filter example selects records based on age and score conditions.
```bash
mlr --csv put '$profit = $revenue - $cost' data.csv
```
```bash
mlr --csv filter '$age >= 18 && $score > 80' data.csv
```
--------------------------------
### JSON Lines example
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Sample JSON Lines data with one JSON object per line. Use with --jsonl or --l2l.
```jsonl
{"apple": 1, "bat": 2, "cog": 3}
{"dish": {"egg": 7, "flint": 8}, "garlic": ""}
```
--------------------------------
### Immediate multi-line statement execution with <...>
Source: https://deepwiki.com/johnkerl/miller/6.1-repl-commands-and-workflow
Wrap a block in < and > to parse and execute it immediately when > is entered. The example defines a function f and then calls it, showing the result 9801.
```text
[mlr] <
... func f(x) {
... return x**2
... }
... >
[mlr] f(99)
9801
```
--------------------------------
### Package manager installation with DESTDIR
Source: https://deepwiki.com/johnkerl/miller/8.2-build-system
Builds and installs Miller into a staging directory for package managers (e.g., RPM, DEB), respecting DESTDIR without modifying the configured prefix.
```bash
make build
make DESTDIR=/tmp/package-root install
```
--------------------------------
### print example in mlr put
Source: https://deepwiki.com/johnkerl/miller/5.8-output-statements
Example of using print inside a put statement. The print output appears immediately when the statement is reached; the modified record flows through the output stream independently.
```bash
mlr put '
print "Processing NR=" . NR . " value=" . $value;
$doubled = $value * 2
' input.csv
```
--------------------------------
### Evaluate expressions in the REPL
Source: https://deepwiki.com/johnkerl/miller/6.1-repl-commands-and-workflow
You can evaluate expressions directly in the REPL. The example shows arithmetic and a function application with output.
```text
[mlr] 1 + 2
3
[mlr] apply([1,2,3,4,5], func(e) {return e ** 3})
[1, 8, 27, 64, 125]
```
--------------------------------
### Create a map with curly braces
Source: https://deepwiki.com/johnkerl/miller/5.2-data-types%3A-strings-and-arrays
Example of creating a map with string keys and mixed-type values, including an array.
```plaintext
map = {"name": "John", "age": 30, "scores": [90, 85, 92]}
```
--------------------------------
### Output redirection examples for emit, print, and dump
Source: https://deepwiki.com/johnkerl/miller/5.8-output-statements
Demonstrates dynamic redirection for emit, print, and dump. The filename or command is a string expression computed per record. When redirecting emit, records are written in the output format; print and dump produce plain text or JSON respectively.
```text
emit @counts[$color] > "/tmp/counts_" . $color . ".txt"
print >> "/tmp/log.txt", "NR=" . NR
dump | "jq ."
```
--------------------------------
### Launch Web-Based pprof for Graphical Analysis
Source: https://deepwiki.com/johnkerl/miller/7.2-performance-and-profiling
Starts the pprof web UI on port 8080, providing a graphical interface for viewing call graphs, flame graphs, and annotated source.
```bash
go tool pprof -http=:8080 cpu.pprof
```
--------------------------------
### Build Miller from Release Tarball
Source: https://deepwiki.com/johnkerl/miller/2-getting-started
Build and install Miller from a release tarball. Requires Go 1.15 or higher and gcc for cgo dependencies. The `make` command can be replaced with `go build github.com/johnkerl/miller/v6/cmd/mlr`, and `make check` with `go test github.com/johnkerl/miller/v6/pkg/... && mlr regtest`.
```bash
tar zxvf mlr-6.17.0.tar.gz
cd mlr-6.17.0
make # or: go build github.com/johnkerl/miller/v6/cmd/mlr
make check # or: go test github.com/johnkerl/miller/v6/pkg/... && mlr regtest
./configure --prefix=/usr/local
make install
```
--------------------------------
### JSON example
Source: https://deepwiki.com/johnkerl/miller/3.3-file-format-support
Sample JSON array of objects, including a nested object and an empty string value. Use with --json or -j.
```json
[
{
"apple": 1,
"bat": 2,
"cog": 3
},
{
"dish": {
"egg": 7,
"flint": 8
},
"garlic": ""
}
]
```
--------------------------------
### Automatic Type Conversion Example
Source: https://deepwiki.com/johnkerl/miller/5.2-data-types%3A-strings-and-arrays
Shows automatic conversion of a string field to a number during arithmetic, with a comment noting the conversion.
```dsl
$sum = $int_field + $string_field # string_field is converted to number if possible
```
--------------------------------
### Create an array with square brackets
Source: https://deepwiki.com/johnkerl/miller/5.2-data-types%3A-strings-and-arrays
Example of creating an array with mixed-type elements, including a map.
```plaintext
array = [1, 2, "three", true, {"key": "value"}]
```
--------------------------------
### Function Help Commands
Source: https://deepwiki.com/johnkerl/miller/2.3-first-steps-with-miller
Function help commands: list functions, show usage, and get help for a specific function.
```bash
mlr -f # List all functions
mlr -F # Show usage for all functions
mlr help function gsub # Help for a specific function
```
--------------------------------
### emit example: emit a map variable with grouping key
Source: https://deepwiki.com/johnkerl/miller/5.8-output-statements
Emits a map variable as a record; key-value pairs become field-value pairs. The optional second argument names the grouping key field in the emitted record. The example counts colors and emits the counts with grouping key 'color'.
```miller
@counts[$color] += 1;
end {
emit @counts, "color"
}
```
--------------------------------
### Verb-Specific Help Commands
Source: https://deepwiki.com/johnkerl/miller/2.3-first-steps-with-miller
Verb-specific help commands: list verbs, show usage, and get help for a specific verb.
```bash
mlr -l # List all verbs
mlr -L # Show usage for all verbs
mlr sort --help # Help for a specific verb
mlr help verb sort # Alternative syntax
```
--------------------------------
### Verify basic CSV data processing with Miller
Source: https://deepwiki.com/johnkerl/miller/2.1-installation-guide
Run these two commands on a CSV file (the documentation uses `example.csv`) to verify basic data processing. The first command outputs CSV, and the second converts input CSV to pretty-printed output. If both produce tabular output without errors, the installation is working correctly.
```bash
mlr --csv cat example.csv
mlr --icsv --opprint cat example.csv
```
--------------------------------
### mlr histogram example
Source: https://deepwiki.com/johnkerl/miller/4.3-statistical-verbs
Example of using histogram with CSV input to histogram the 'quantity' field.
```bash
mlr --csv histogram -f quantity
```
--------------------------------
### Working with Maps and Arrays in REPL
Source: https://deepwiki.com/johnkerl/miller/6.1-repl-commands-and-workflow
Shows how to enter maps and arrays in the REPL and apply a function to an array. The output for each input is displayed.
```text
[mlr] {"a": 1, "b": 2, "c": 3}
{
"a": 1,
"b": 2,
"c": 3
}
[mlr] [1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]
[mlr] apply([1, 2, 3, 4, 5], func(e) { return e * e })
[1, 4, 9, 16, 25]
```
--------------------------------
### REPL Session Demonstrating Out-of-Stream Variable Persistence
Source: https://deepwiki.com/johnkerl/miller/6-interactive-repl
Example REPL session showing how out-of-stream variables (@sum) persist across multiple :read commands, accumulating values from each record. The session initializes an accumulator, adds the value from the first record, then adds the value from the second record after another :read, and finally displays the total.
```text
[mlr] :open data.csv
[mlr] :read
[mlr] @sum = 0 # Initialize accumulator
[mlr] @sum += $value # First record
[mlr] :read
[mlr] @sum += $value # Second record (accumulates)
[mlr] @sum # Shows total across both records
```
--------------------------------
### Two-Pass Algorithm Example with Out-of-Stream Variables
Source: https://deepwiki.com/johnkerl/miller/5.3-variables-and-scoping
Demonstrates a two-pass algorithm using out-of-stream variables. The first pass collects all records and computes a sum; the end block performs a second pass to calculate percentages and emit the enriched records.
```dsl
# First pass: collect all records
@records[NR] = $*;
@sum += $value;
end {
# Second pass: compute percentages
for (i in @records) {
@records[i]["percentage"] = @records[i]["value"] / @sum * 100;
emit @records[i];
}
}
```
--------------------------------
### Chaining verbs with then
Source: https://deepwiki.com/johnkerl/miller/1-introduction-to-miller
Demonstrates how to chain multiple Miller verbs using 'then'. This example reads a CSV file, computes min/mean/max statistics on the 'quantity' field, and then sorts the output by the 'color' field.
```bash
mlr --csv stats1 -a min,mean,max -f quantity then sort -f color example.csv
```
--------------------------------
### JSON input with varying fields
Source: https://deepwiki.com/johnkerl/miller/3.1-data-processing-model
Example input records with heterogeneous fields: first record has name and age, second has name and role, third has all three. Each record independently determines which fields to output.
```json
{"name": "alice", "age": 30}
{"name": "bob", "role": "admin"}
{"name": "carol", "age": 25, "role": "user"}
```
--------------------------------
### Reading and modifying a record with :open, :read, :context, :write
Source: https://deepwiki.com/johnkerl/miller/6.1-repl-commands-and-workflow
Shows the workflow of opening a file, reading the first record, viewing context and full record, modifying a field, and writing the record. The output shows the record fields and the result of adding $x and $i.
```text
[mlr] :open foo.dat
[mlr] :read
[mlr] :context
FILENAME="foo.dat",FILENUM=1,NR=1,FNR=1
[mlr] $*
{
"a": "eks",
"b": "wye",
"i": 4,
"x": 0.38139939387114097,
"y": 0.13418874328430463
}
[mlr] $z = $x + $i
[mlr] :write
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463,z=4.381399393871141
```
--------------------------------
### Unix pipeline examples with Miller
Source: https://deepwiki.com/johnkerl/miller/3-core-concepts
Shows Miller in Unix pipelines: decompressing gzip input and sorting/filtering, and cutting fields then sorting and counting unique values.
```bash
gunzip -c data.csv.gz | mlr --csv sort -f name | grep Smith
mlr --csv cut -f name,age data.csv | sort | uniq -c
```
--------------------------------
### Get help for Miller verbs with mlr help and --help
Source: https://deepwiki.com/johnkerl/miller/4-verbs-reference
Use these commands to access built-in verb documentation. The first shows usage for the sort verb, the second for stats1, and the third searches for help containing 'gmt'.
```bash
mlr sort --help
mlr help verb stats1
mlr help find gmt
```
--------------------------------
### Quick Build and Test Commands
Source: https://deepwiki.com/johnkerl/miller/8.2-build-system
Commands for rapid iteration: 'make' or 'make build' to build, and 'make check' or 'make unit-test regression-test' to run tests.
```bash
make # or: make build
make check # or: make unit-test regression-test
```
--------------------------------
### Local Development and Testing Commands
Source: https://deepwiki.com/johnkerl/miller/8.6-documentation-system
Commands to build and view documentation locally. `make dev` performs a complete documentation rebuild, `make man` builds man pages only, `make docs` builds web documentation only, and `man ./man/man1/mlr.1` views the local man page.
```bash
make dev # Complete documentation rebuild
make man # Man pages only
make docs # Web documentation only
man ./man/man1/mlr.1 # View local man page
```
--------------------------------
### Out-of-Stream Variable Initialization Behavior
Source: https://deepwiki.com/johnkerl/miller/5.3-variables-and-scoping
Illustrates the default initialization behavior of out-of-stream variables: arithmetic operations start at 0, multiplication at 1, and string concatenation at an empty string. Explicit initialization in a begin block is recommended for clarity.
```dsl
# These work without explicit initialization
@sum += $x # @sum starts at 0
@product *= $value # @product starts at 1
@message .= $text # @message starts at ""
# Explicit initialization (recommended for clarity)
begin {
@sum = 0;
@count = 0;
@groups = {};
}
```
--------------------------------
### Field assignment example with mlr put
Source: https://deepwiki.com/johnkerl/miller/5.8-output-statements
Example of using field assignment in an mlr put command to compute total and tax from input.csv.
```bash
mlr put '$total = $price * $quantity; $tax = $total * 0.07' input.csv
```
--------------------------------
### Using rlwrap for History Editing
Source: https://deepwiki.com/johnkerl/miller/6.1-repl-commands-and-workflow
Shows how to launch the REPL with rlwrap to add command history and line editing, and a common alias for convenience.
```bash
rlwrap mlr repl
```
```bash
alias mrpl='rlwrap mlr repl'
```
--------------------------------
### List DSL help via mlr command-line flags
Source: https://deepwiki.com/johnkerl/miller/5-domain-specific-language-%28dsl%29
Commands to list built-in functions, DSL keywords, and print the Abstract Syntax Tree (AST) for expressions.
```bash
mlr -f
mlr -F
mlr -k
mlr -K
mlr help function gsub
mlr help find gmt
mlr put -p '...'
mlr put -v '...'
```
--------------------------------
### Mermaid flowchart of documentation generation pipeline
Source: https://deepwiki.com/johnkerl/miller/8.3-cicd-pipeline
Shows the flow from source files (mlr executable, .md.in templates, example data files) through man page generation and markdown processing to final HTML website documentation. Use it to understand the build and documentation pipeline.
```mermaid
flowchart TD
subgraph "Source Files"
SourceCode["mlr executable"]
MarkdownTemplates["*.md.in templates"]
DocExamples["Example data files"]
end
subgraph "Manual Page Generation"
MkmanScript["man/mkman.rb"]
ManPages["Man Pages (mlr.1)"]
TextVersion["manpage.txt"]
end
subgraph "Markdown Processing"
GenmdScript["docs/src/genmds"]
ProcessTemplates["Process .md.in Files"]
LiveCodeExamples["Generate Live Code Examples"]
MarkdownFiles["Final Markdown Files"]
end
subgraph "Website Generation"
GenerateHTML["Generate HTML"]
MillerWebsite["Miller Website Documentation"]
end
SourceCode --> MkmanScript
MkmanScript --> ManPages
MkmanScript --> TextVersion
MarkdownTemplates --> GenmdScript
DocExamples --> GenmdScript
GenmdScript --> ProcessTemplates
ProcessTemplates --> LiveCodeExamples
LiveCodeExamples --> MarkdownFiles
TextVersion --> MarkdownFiles
MarkdownFiles --> GenerateHTML
GenerateHTML --> MillerWebsite
```
--------------------------------
### Run Tests with Make
Source: https://deepwiki.com/johnkerl/miller/8-development-and-contributing
Commands to execute the full test suite or specific test categories using Make.
```bash
# Run all tests
make check
# Or run individually
make unit-test # Go unit tests
make regression-test # End-to-end regression tests
```
--------------------------------
### Example: Processing 100GB file with 8GB RAM
Source: https://deepwiki.com/johnkerl/miller/3.1-data-processing-model
Shows two Miller commands for processing a large file: a streaming filter that works within memory limits, and a two-pass sort that requires memory proportional to file size and would fail.
```bash
mlr --csv filter '$quantity > 100' huge.csv
```
```bash
mlr --csv sort -n quantity huge.csv
```
--------------------------------
### Documentation Generation Pipeline (Mermaid)
Source: https://deepwiki.com/johnkerl/miller/3.4-help-and-documentation-system
Mermaid diagram showing the documentation generation pipeline: source files (.md.in templates, Go source annotations, live examples) feed into the build process (make dev, Markdown generation, MkDocs build) to produce generated artifacts (.md files, HTML site) that are published to GitHub and ReadTheDocs.
```mermaid
graph TB
subgraph "Source Files"
MDIn["*.md.in Templates
docs/src/*.md.in"]
CodeFiles["Go Source Code
Annotations & signatures"]
Examples["Live Examples
GENMD-RUN-COMMAND
Executed during build"]
end
subgraph "Build Process"
MakeDev["make dev
Orchestrates build"]
GenMD["Markdown Generation
Processes .md.in templates
Executes live examples"]
MkDocs["MkDocs Build
Static site generator"]
end
subgraph "Generated Artifacts"
MD["*.md Files
docs/src/*.md
(DO NOT EDIT warnings)"]
HTMLSite["HTML Site
docs/site/"]
SiteIndex["site/index.html"]
end
subgraph "Publishing"
GitHubRepo["GitHub Repository
docs/ directory"]
ReadTheDocs["ReadTheDocs Platform
miller.readthedocs.io"]
end
MDIn --> GenMD
CodeFiles --> GenMD
Examples --> GenMD
MakeDev --> GenMD
GenMD --> MD
MD --> MkDocs
MkDocs --> HTMLSite
HTMLSite --> SiteIndex
MD --> GitHubRepo
GitHubRepo --> ReadTheDocs
ReadTheDocs --> WebAccess["Public Web Access"]
```
--------------------------------
### Format Conversion Functions Examples
Source: https://deepwiki.com/johnkerl/miller/5.7-operators-and-type-system
Examples of format conversion functions: fmtnum formats a number with printf-style, hexfmt converts an integer to hexadecimal, and fmtifnum formats only if the value is numeric.
```dsl
$price = fmtnum($raw_price, "%.2f"); # "19.99"
$hex_id = hexfmt($decimal_id); # "0x4a2f"
$maybe_number = fmtifnum($field, "%.3f"); # Formats if number, else unchanged
```
--------------------------------
### Work with data files in the REPL
Source: https://deepwiki.com/johnkerl/miller/6.1-repl-commands-and-workflow
Use colon commands ':open' and ':read' to load a CSV file and then display the current record with '$*'. The output shows the record fields.
```text
[mlr] :open example.csv
[mlr] :read
[mlr] $*
{
"color": "yellow",
"shape": "triangle",
"flag": "true",
"k": 1,
"index": 11,
"quantity": 43.6498,
"rate": 9.8870
}
```
--------------------------------
### Customizing REPL Prompts with Environment Variables
Source: https://deepwiki.com/johnkerl/miller/6.1-repl-commands-and-workflow
Shows how to set the primary and continuation prompts using environment variables MLR_REPL_PS1 and MLR_REPL_PS2.
```bash
export MLR_REPL_PS1='mlr> '
export MLR_REPL_PS2=' '
```
--------------------------------
### emit1 example: emit a single out-of-stream variable
Source: https://deepwiki.com/johnkerl/miller/5.8-output-statements
Emits a single out-of-stream scalar or map variable directly as a record. The example accumulates a sum in @sum and emits it in an end block. Output (DKVP): sum=4986.019681679581.
```miller
@sum += $x;
end {
emit1 @sum
}
```
--------------------------------
### dump example in mlr put
Source: https://deepwiki.com/johnkerl/miller/5.8-output-statements
Example of using dump in an end block. The output is JSON, e.g., {"count":10,"sum":4986.019681679581}. dump with no argument is equivalent to printing @* as JSON.
```bash
mlr put '
@count += 1;
@sum += $value;
end { dump }
' input.csv
```
--------------------------------
### UTF-8 field names and filter example
Source: https://deepwiki.com/johnkerl/miller/1.3-what%27s-new-in-miller-6
Illustrates using non-ASCII field names and values with Miller's filter. The example shows filtering a CSV file for a Greek field name 'σχήμα' with value 'κύκλος'.
```shell
mlr --c2p filter '$σχήμα == "κύκλος"' παράδειγμα.csv
```
--------------------------------
### emitf example: emit flat record from listed variables
Source: https://deepwiki.com/johnkerl/miller/5.8-output-statements
Emits a flat record whose fields are the listed out-of-stream variable names. The example accumulates n and sum, then emits them in an end block. Output: n=10,sum=4986.019681679581.
```miller
@n += 1;
@sum += $x;
end {
emitf @n, @sum
}
```
--------------------------------
### Execute Development Workflow
Source: https://deepwiki.com/johnkerl/miller/8-development-and-contributing
Runs the full development cycle including formatting, building, testing, and documentation generation.
```bash
make dev
```
--------------------------------
### Build flow diagram (Mermaid)
Source: https://deepwiki.com/johnkerl/miller/2.2-building-from-source
Mermaid diagram showing the build flow from source tree through go build to the binary.
```mermaid
flowchart TD
SOURCE["Source tree\ngithub.com/johnkerl/miller/v6"]
GOMOD["go.mod / go.sum\nDependency manifest"]
GOBUILD["go build\ngithub.com/johnkerl/miller/v6/cmd/mlr"]
MAIN["cmd/mlr/main.go\nmain()"]
BINARY["./mlr (or .\\mlr.exe on Windows)"]
SOURCE --> GOMOD
SOURCE --> MAIN
MAIN --> GOBUILD
GOMOD --> GOBUILD
GOBUILD --> BINARY
```
--------------------------------
### `having-fields` predicate filtering examples
Source: https://deepwiki.com/johnkerl/miller/4.2-data-transformation-verbs
Examples of `having-fields` with `--any-matching`, `--all-matching`, and `--none-matching` to pass or drop entire records based on field name regex matching. Each shows a regex pattern that determines whether the record is retained.
```text
mlr having-fields --any-matching '^[a-z]'
mlr having-fields --all-matching '^[a-z]'
mlr having-fields --none-matching '^[A-Z]'
```
--------------------------------
### General Help Commands
Source: https://deepwiki.com/johnkerl/miller/2.3-first-steps-with-miller
General help commands: overview and list of help categories.
```bash
mlr --help # Overview and help topics
mlr help topics # List all help categories
```
--------------------------------
### Example Miller verb invocations
Source: https://deepwiki.com/johnkerl/miller/4.1-verb-overview-and-categories
Three example invocations of Miller verbs: sorting CSV data by hostname, computing a sum statistic on JSON data, and cutting fields from CSV input while printing as pretty-printed output. Each uses different global flags and verb options.
```text
mlr --csv sort -f hostname data.csv
mlr --json stats1 -a sum -f quantity data.json
mlr --icsv --opprint cut -f name,age input.csv
```
--------------------------------
### Common Miller verb examples
Source: https://deepwiki.com/johnkerl/miller/3.2-command-line-interface
Examples of common Miller verbs: cat for pass-through, cut for field selection, sort for ordering, put for DSL field modification, filter for DSL record selection, stats1 for statistics, head for first N records, and join for merging files.
```bash
mlr --csv cat data.csv
```
```bash
mlr cut -f name,age data.csv
```
```bash
mlr sort -f age -nr salary data.csv
```
```bash
mlr put '$total = $price * $qty' data.csv
```
```bash
mlr filter '$age > 21' data.csv
```
```bash
mlr stats1 -a mean,sum -f salary -g dept data.csv
```
```bash
mlr head -n 10 data.csv
```
```bash
mlr join -j id -f lookup.csv data.csv
```
--------------------------------
### `label` positional renaming examples
Source: https://deepwiki.com/johnkerl/miller/4.2-data-transformation-verbs
Examples of the `label` verb: first renames fields positionally from a headerless input where fields are separated by spaces; second pairs `label` with `--csv --implicit-csv-header` to attach headers to a headerless CSV file. Both rename fields by order, not by current name.
```text
mlr --inidx --ifs ' ' label host,status,count
```
```text
mlr --csv --implicit-csv-header label name,age,role data.csv
```
--------------------------------
### Run staticcheck via make
Source: https://deepwiki.com/johnkerl/miller/8.4-testing-framework
Use 'make staticcheck' to run static analysis. The equivalent command is 'staticcheck ./pkg/... ./cmd/mlr/...'.
```bash
make staticcheck
# Equivalent to:
staticcheck ./pkg/... ./cmd/mlr/...
```
--------------------------------
### Flag Help Commands
Source: https://deepwiki.com/johnkerl/miller/2.3-first-steps-with-miller
Flag help commands: list flags and get help for CSV-related flags.
```bash
mlr -g # List all flags
mlr help flag csv # Help for CSV-related flags
```
--------------------------------
### Run unit tests with coverage
Source: https://deepwiki.com/johnkerl/miller/8.4-testing-framework
Runs unit tests with coverage reporting. The first command shows basic coverage, while the second and third generate a detailed HTML coverage report.
```bash
go test -cover github.com/johnkerl/miller/v6/pkg/...
# Or for detailed coverage report:
go test -coverprofile=coverage.out github.com/johnkerl/miller/v6/pkg/...
go tool cover -html=coverage.out
```
--------------------------------
### go.yml workflow flowchart
Source: https://deepwiki.com/johnkerl/miller/8.3-cicd-pipeline
Visualizes the go.yml workflow: triggers, build matrix (ubuntu-latest, macos-latest, windows-latest), and per-OS steps from checkout through artifact upload. Useful for understanding the CI pipeline structure and step order.
```mermaid
flowchart TD
Trigger["Push/PR to main"]
subgraph Matrix["Build Matrix (parallel)"]
Ubuntu["ubuntu-latest"]
MacOS["macos-latest"]
Windows["windows-latest"]
end
subgraph Steps["Steps per OS"]
Checkout["actions/checkout@8e8c483"]
SetupGo["actions/setup-go@4b73464\nGo 1.24"]
Build["make build\n→ go build github.com/johnkerl/miller/v6/cmd/mlr"]
UnitTest["make unit-test\n→ go test github.com/johnkerl/miller/v6/pkg/..."]
RegTest["test/../mlr regtest -S"]
PrepareArtifact["mkdir -p bin/${{matrix.os}}\ncp mlr[.exe] to bin/"]
UploadArtifact["actions/upload-artifact@bbbca2d\nname: mlr-${{matrix.os}}"]
end
Trigger --> Matrix
Matrix --> Ubuntu
Matrix --> MacOS
Matrix --> Windows
Ubuntu --> Checkout
MacOS --> Checkout
Windows --> Checkout
Checkout --> SetupGo
SetupGo --> Build
Build --> UnitTest
UnitTest --> RegTest
RegTest --> PrepareArtifact
PrepareArtifact --> UploadArtifact
```
--------------------------------
### Use --from for pipelined streaming
Source: https://deepwiki.com/johnkerl/miller/7.3-streaming-and-memory-considerations
Demonstrates using the '--from' flag to stream a file without loading it fully into memory, enabling efficient pipelined processing.
```bash
# Stream processing without loading full file
mlr --csv --from huge.csv filter '$amount > 1000' then cut -f id,amount
```