Commands

38 Unix commands, reimagined as type-safe streaming operations.

Text Processing

cat stateful-map

Passes lines through with optional transformations including line numbering, blank line squeezing, and non-printing character display.

shell
gloo.Run(source, cat.Cat(cat.CatNumberLines, cat.CatShowEnds), sink)
flags & options
  • --n, --number-lines — Number all output lines
  • --b, --number-non-blank — Number non-blank output lines only
  • --E, --show-ends — Display $ at end of each line
  • --T, --show-tabs — Display TAB characters as ^I
  • --s, --squeeze-blank — Suppress repeated empty output lines
  • --A, --show-all — Equivalent to show-ends + show-tabs + show-non-printing
  • --v, --show-non-printing — Use caret and meta notation for non-printing characters
  • --trim-spaces — Trim trailing whitespace from each line
comm accumulate

Compares two sorted inputs line by line, outputting three columns: lines only in first input, lines only in second input, and lines in both.

shell
gloo.Run(source, comm.Comm(comm.CommInput(input2)), sink)
cut map

Selects fields, bytes, or characters from each input line by position, equivalent to the Unix cut utility.

shell
gloo.Run(source, cut.Cut(cut.CutFields(1, 3), cut.CutDelimiter(",")), sink)
flags & options
  • --f, --fields — Select fields by 1-based position
  • --d, --delimiter — Field delimiter (default: tab)
  • --b, --bytes — Select bytes by position range
  • --c, --chars — Select characters (runes) by position range
  • ---complement, --complement — Invert the selection for any mode
diff accumulate

Computes a simple line diff between stdin and a second input, reporting lines that differ with < and > prefixes.

shell
gloo.Run(source, diff.Diff(diff.DiffInput(input2)), sink)
grep filter

Filters lines containing the given pattern with support for regex, case-insensitive, inverted, word, and whole-line matching.

shell
gloo.Run(source, grep.Grep("ERROR", grep.GrepIgnoreCase), sink)
flags & options
  • --i, --ignore-case — Case-insensitive matching
  • --v, --invert — Invert match (print non-matching lines)
  • --x, --whole-line — Match only if entire line equals pattern
  • --E, --extended — Interpret pattern as extended regex
  • --w, --word — Match pattern only at word boundaries
  • --n, --line-numbers — Prepend line number to each matching line
  • --c, --count — Count matching lines instead of printing them
join accumulate

Joins two sorted inputs on the first field, combining matching lines from both inputs.

shell
gloo.Run(source, join.Join(join.JoinInput(input2)), sink)
flags & options
  • --t, --separator — Field separator (default: space)
nl stateful-map

Numbers lines from input with configurable body numbering, separator, start value, increment, width, and format.

shell
gloo.Run(source, nl.Nl(nl.NlStart(1), nl.NlWidth(4)), sink)
flags & options
  • --b, --body — Which lines to number: a (all), t (non-empty), n (none)
  • --s, --separator — Separator between number and line (default: tab)
  • --v, --start — Starting line number (default: 1)
  • --i, --increment — Line number increment (default: 1)
  • --w, --width — Field width for line numbers (default: 6)
  • --n, --format — Number format: ln (left), rn (right, default), rz (right zero-padded)
paste aggregate

Merges all input lines into a single output line joined by a delimiter (default: tab).

shell
gloo.Run(source, paste.Paste(paste.PasteDelimiter(",")), sink)
flags & options
  • --d, --delimiter — Delimiter used to join lines (default: tab)
  • --s, --serial — Join lines serially
rev map

Reverses each input line character by character.

shell
gloo.Run(source, rev.Rev(), sink)
sed expand

Applies sed expressions to each input line including substitution, deletion, printing, transliteration, and address ranges.

shell
gloo.Run(source, sed.Sed("s/old/new/g"), sink)
flags & options
  • --n, --quiet — Suppress default output; only print when explicitly requested
  • --e, --expression — Add additional sed expression to apply in order
tac accumulate

Reverses the order of input lines. Optionally splits on a custom record separator instead of newlines.

shell
gloo.Run(source, tac.Tac(), sink)
flags & options
  • --s, --separator — Split on a custom record separator instead of newlines
tr map

Translates, deletes, or squeezes characters using character set mappings with support for ranges like a-z.

shell
gloo.Run(source, tr.Tr(tr.TrSet("a-z"), tr.TrSet("A-Z")), sink)
flags & options
  • --d, --delete — Delete characters in set1 from input
  • --s, --squeeze — Squeeze runs of repeated characters to a single character
  • --c, --complement — Use complement of set1
wc aggregate

Counts lines, words, and bytes from the input stream. With no flags, all three counts are shown space-separated.

shell
gloo.Run(source, wc.Wc(wc.WcLines), sink)
flags & options
  • --l, --lines — Count lines
  • --w, --words — Count words
  • --c, --bytes — Count bytes
  • --m, --chars — Count characters (runes)
  • --L, --max-line-length — Report the maximum line length in bytes

Stream Selection

head stateful-filter

Outputs the first N lines of input (default: 10). Supports byte-count mode for raw byte output.

shell
gloo.Run(source, head.Head(head.HeadLines(5)), sink)
flags & options
  • --n, --lines — Number of lines to output (default: 10)
  • --c, --bytes — Number of bytes to output
shuf accumulate

Randomly shuffles input lines with optional count limit, deterministic seed, integer range generation, and echo mode.

shell
gloo.Run(source, shuf.Shuf(shuf.ShufCount(5)), sink)
flags & options
  • --n, --count — Limit output to N lines
  • ---seed, --seed — Random seed for deterministic output
  • --i, --input-range — Generate and shuffle integers from lo to hi
  • --e, --echo — Shuffle the given arguments instead of stdin
sort accumulate

Sorts input lines with support for reverse, numeric, unique, case-insensitive, field-based, random, and stable sorting.

shell
gloo.Run(source, sort.Sort(sort.SortReverse, sort.SortNumeric), sink)
flags & options
  • --r, --reverse — Reverse sort order
  • --n, --numeric — Compare according to numeric value
  • --u, --unique — Output only unique lines
  • --f, --ignore-case — Case-insensitive comparison
  • --k, --field — Sort by field position (1-based)
  • --t, --delimiter — Field delimiter (default: space)
  • --R, --random — Randomly shuffle lines
  • --b, --ignore-leading-blanks — Ignore leading blanks
  • --s, --stable — Stabilize sort by disabling last-resort comparison
tail accumulate

Outputs the last N lines of input (default: 10). Supports byte-count mode for raw byte output.

shell
gloo.Run(source, tail.Tail(tail.TailLines(5)), sink)
flags & options
  • --n, --lines — Number of lines to output (default: 10)
  • --c, --bytes — Number of bytes to output
uniq stateful-filter

Filters adjacent duplicate lines from input with support for counting, duplicate-only, unique-only, and case-insensitive comparison.

shell
gloo.Run(source, uniq.Uniq(uniq.UniqCount), sink)
flags & options
  • --c, --count — Prepend occurrence counts to output lines
  • --d, --duplicates-only — Only output repeated lines
  • --u, --unique-only — Only output lines that are not repeated
  • --i, --ignore-case — Case-insensitive comparison
  • --f, --skip-fields — Skip the first N whitespace-separated fields before comparison
  • --s, --skip-chars — Skip the first N characters before comparison
  • --w, --compare-width — Limit comparison to the first N characters

Data Transformation

awk stateful-map

Processes input lines through an awk-style program with Begin, Condition, Action, and End phases, supporting field splitting and variables.

shell
gloo.Run(source, awk.Awk(program, awk.AwkFieldSeparator(",")), sink)
flags & options
  • --F, --field-separator — Input field separator (default: space)
  • --v OFS, --output-field-separator — Output field separator (default: space)
  • --v, --variable — Set awk variable (name=value)
base64 aggregate

Encodes input to base64 (default) or decodes base64 input, with optional line wrapping for encoded output.

shell
gloo.Run(source, base64.Base64(base64.Base64Decode), sink)
flags & options
  • --d, --decode — Decode base64 input instead of encoding
  • --w, --wrap — Wrap encoded output at column width
  • --w N, --wrap-width — Column width for line wrapping (default: 76)
hexdump aggregate

Formats input as a hex dump with running byte offsets and optional canonical mode showing ASCII printable characters.

shell
gloo.Run(source, hexdump.Hexdump(hexdump.HexdumpCanonical), sink)
flags & options
  • --C, --canonical — Canonical hex+ASCII display
json map

Parses each input line as JSON and re-emits it in compact form. Each input line must be valid JSON.

shell
gloo.Run(source, json.Json(), sink)
json fromcsv map

Converts CSV input to newline-delimited JSON output, using the header row as object keys for each subsequent row.

shell
gloo.Run(source, fromcsv.FromCsv(), sink)
flags & options
  • --d, --delimiter — CSV field delimiter (default: comma)
  • ---no-header, --no-header — Generate column names (col1, col2, ...) instead of reading header row
  • ---trim, --trim-spaces — Trim leading whitespace from fields
json fromtoml map

Converts TOML input to pretty-printed JSON output, allowing TOML files to be processed by JSON commands.

shell
gloo.Run(source, fromtoml.FromToml(), sink)
json fromtsv map

Converts TSV (tab-separated values) input to newline-delimited JSON output, using the header row as object keys.

shell
gloo.Run(source, fromtsv.FromTsv(), sink)
flags & options
  • ---no-header, --no-header — Generate column names (col1, col2, ...) instead of reading header row
  • ---trim, --trim-spaces — Trim leading whitespace from fields
json fromyaml map

Converts YAML input to pretty-printed JSON output, allowing YAML files to be processed by JSON commands.

shell
gloo.Run(source, fromyaml.FromYaml(), sink)
json pluck map

Extracts specified fields from JSON objects, emitting only the selected fields as a new JSON object.

shell
gloo.Run(source, pluck.Pluck("name", "age"), sink)
json select filter

Filters JSON values based on a condition function, with built-in condition builders for field existence, equality, and predicate matching.

shell
gloo.Run(source, selectcmd.Select(selectcmd.HasField("name")), sink)

File / Line Operations

basename map

Extracts the filename component of each input path with optional suffix stripping.

shell
gloo.Run(source, basename.Basename(basename.BasenameSuffix(".go")), sink)
flags & options
  • --s, --suffix — Suffix to strip from the basename result
dirname map

Extracts the directory component of each input path.

shell
gloo.Run(source, dirname.Dirname(), sink)
emit map

Produces output on both stdout and stderr, useful for testing pipelines and demonstrating error handling.

shell
gloo.Run(emit.Emit("hello", "warning"), sink)
split expand

Splits each input line on a delimiter into multiple output lines. With no options, splits on whitespace.

shell
gloo.Run(source, split.Split(split.SplitDelim(",")), sink)
flags & options
  • --d, --delimiter — Field delimiter for splitting (default: whitespace)
tee map

Passes lines through unchanged while writing each line to the provided writers as a side effect.

shell
gloo.Run(source, tee.Tee(&buf), sink)
xargs expand

Splits each input line into fields and groups them into output lines of at most N fields. Default emits each field as a separate line.

shell
gloo.Run(source, xargs.Xargs(xargs.XargsMaxArgs(3)), sink)
flags & options
  • --n, --max-args — Maximum number of fields per output line (default: 1)

Utility

capture aggregate

Captures stdin to the provided writers, useful as a pipeline sink for programmatic output capture instead of writing to os.Stdout.

shell
gloo.Run(source, capture.Capture(&stdout, &stderr))
echo expand

Returns a Source that emits its arguments joined by spaces as a single line.

shell
gloo.Run(echo.Echo("hello", "world"), sink)
exec map

Forks an external command with the given arguments, wiring stdin/stdout/stderr to the pipeline.

shell
gloo.Run(source, exec.Exec("ls", "-la"), sink)
flags & options
  • --C, --working-dir — Working directory for the command
  • --e, --env — Environment variable to set
  • --S, --shell — Shell to use for command execution
  • --use-shell — Execute command through a shell
  • --ignore-errors — Continue pipeline on command failure
  • --q, --quiet — Suppress stderr output
  • --i, --interactive — Run command in interactive mode
  • --inherit-env — Inherit parent environment variables
find expand

Returns a Source that walks a directory tree and emits matching paths with optional name glob, type filter, and depth limit.

shell
gloo.Run(find.Find(".", find.FindName("*.go"), find.FindType("f")), sink)
flags & options
  • --name, --name — Glob pattern for matching filenames
  • --type, --type — Filter by type: f (files) or d (directories)
  • --maxdepth, --max-depth — Limit walk depth relative to the root
git map

Forks git with the given subcommand and arguments, wiring the pipeline stream through the git process.

shell
gloo.Run(source, git.Git("log", "--oneline"), sink)
ls expand

Returns a Source that lists directory entries with optional hidden file display and recursive traversal.

shell
gloo.Run(ls.Ls(".", ls.LsAll, ls.LsRecursive), sink)
flags & options
  • --a, --all — Show hidden entries (starting with .)
  • --R, --recursive — List directory contents recursively
perl map

Forks perl with a script, supporting loop mode, print mode, and auto-split mode for one-liner text processing.

shell
gloo.Run(source, perl.Perl("s/foo/bar/g", perl.PerlPrint), sink)
flags & options
  • --n, --loop — Process input line by line
  • --p, --print — Process and print each line
  • --a, --auto-split — Auto-split input fields
seq expand

Returns a Source that generates a numeric sequence. Supports single endpoint, start-end, and start-step-end forms.

shell
gloo.Run(seq.Seq(1, 10), sink)
flags & options
  • --w, --equal-width — Zero-pad numbers to equal width
  • --s, --separator — Join all numbers with separator, emit as single item
  • --f, --format — Printf-style format string for each number
while map

Executes a body function for each input line, emitting the results as a general-purpose per-line transformation.

shell
gloo.Run(source, while.While(func(line []byte) ([]byte, error) { return line, nil }), sink)
yes expand

Returns a Source that emits a string repeatedly until context is cancelled. Default string is y.

shell
gloo.Run(yes.Yes(yes.YesText("ok"), yes.YesCount(10)), sink)
flags & options
  • --text — String to repeat (default: y)
  • --n, --count — Limit number of repetitions (0 = infinite)