Commands

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

Text Processing

cat stateful-map

Passes lines through unchanged, optionally numbering every line or only the non-blank lines.

go
gloo.Run(source, cat.Cat(cat.CatNumberLines), sink)
options
  • CatNumberLines -n — Number all output lines
  • CatNumberNonBlank -b — Number non-blank output lines only (overrides -n)
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.

go
gloo.Run(source, comm.Comm(comm.CommInput(input2)), sink)
options
  • CommSuppressColumn1 -1 — Suppress column 1 (lines only in the first input)
  • CommSuppressColumn2 -2 — Suppress column 2 (lines only in the second input)
  • CommSuppressColumn3 -3 — Suppress column 3 (lines common to both inputs)
  • CommInput(lines) — Supply the second input as raw lines
cut map

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

go
gloo.Run(source, cut.Cut(cut.CutFields(1, 3), cut.CutDelimiter(",")), sink)
options
  • CutFields(1, 3) -f — Select fields by 1-based position
  • CutDelimiter(d) -d — Field delimiter (default: tab)
  • CutBytes("1-3,5") -b — Select bytes by position range
  • CutChars("1-3,5") -c — Select characters (runes) by position range
  • CutComplement --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.

go
gloo.Run(source, diff.Diff(diff.DiffInput(input2)), sink)
options
  • DiffUnified -u — Output a unified diff instead of the default ed-style diff
  • DiffInput(lines) — Supply the second input as raw lines
grep filter

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

go
gloo.Run(source, grep.Grep("ERROR", grep.GrepIgnoreCase), sink)
options
  • GrepIgnoreCase -i — Case-insensitive matching
  • GrepInvert -v — Invert match (print non-matching lines)
  • GrepWholeLine -x — Match only if entire line equals pattern
  • GrepExtended -E — Interpret pattern as extended regex
  • GrepWord -w — Match pattern only at word boundaries
  • GrepLineNumbers -n — Prepend line number to each matching line
  • GrepCount -c — Count matching lines instead of printing them
join accumulate

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

go
gloo.Run(source, join.Join(join.JoinInput(input2)), sink)
options
  • JoinSeparator(sep) -t — Field separator (default: whitespace)
  • JoinInput(lines) — Supply the second input as raw lines
nl stateful-map

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

go
gloo.Run(source, nl.Nl(nl.NlStart(1), nl.NlWidth(4)), sink)
options
  • NlBodyAll -b — Which lines to number: NlBodyAll, NlBodyNonEmpty, or NlBodyNone
  • NlSep(s) -s — Separator between number and line (default: tab)
  • NlStart(n) -v — Starting line number (default: 1)
  • NlIncrement(n) -i — Line number increment (default: 1)
  • NlWidth(n) -w — Field width for line numbers (default: 6)
  • NlFormat(fmt) -n — Number format: NlFormatLN (left), NlFormatRN (right, default), NlFormatRZ (right zero-padded)
paste accumulate

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

go
gloo.Run(source, paste.Paste(paste.PasteDelimiter(",")), sink)
options
  • PasteDelimiter(d) -d — Delimiter used to join lines (default: tab)
  • PasteSerial -s — Join lines serially into a single row
rev map

Reverses each input line character by character.

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

Applies a single sed expression to each input line, supporting substitution, deletion, printing, transliteration, and address ranges.

go
gloo.Run(source, sed.Sed("s/old/new/g"), sink)
tac accumulate

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

go
gloo.Run(source, tac.Tac(), sink)
options
  • TacSep(s) -s — 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.

go
gloo.Run(source, tr.Tr("a-z", "A-Z"), sink)
options
  • TrDelete -d — Delete characters in set1 from input
  • TrSqueeze -s — Squeeze runs of repeated characters to a single character
  • TrComplement -c — Use the complement of set1
wc aggregate

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

go
gloo.Run(source, wc.Wc(wc.WcLines), sink)
options
  • WcLines -l — Count lines
  • WcWords -w — Count words
  • WcBytes -c — Count bytes
  • WcChars -m — Count characters (runes)
  • WcMaxLineLength -L — 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.

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

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

go
gloo.Run(source, shuf.Shuf(shuf.ShufCount(5)), sink)
options
  • ShufCount(n) -n — Limit output to N lines
  • ShufSeed(n) — Random seed for deterministic output
  • ShufRange(lo, hi) -i — Generate and shuffle integers from lo to hi
  • ShufEcho(args...) -e — Shuffle the given arguments instead of stdin
sort accumulate

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

go
gloo.Run(source, sort.Sort(sort.SortReverse, sort.SortNumeric), sink)
options
  • SortReverse -r — Reverse sort order
  • SortNumeric -n — Compare according to numeric value
  • SortHumanNumeric -h — Compare human-readable sizes (2K < 1M)
  • SortMonthSort -M — Compare month names (Jan < Feb < ...)
  • SortVersionSort -V — Natural/version sort (v1.2 < v1.10)
  • SortUnique -u — Output only unique lines
  • SortIgnoreCase -f — Case-insensitive comparison
  • SortField(n) -k — Sort by field position (1-based)
  • SortDelimiter(d) -t — Field delimiter (default: whitespace)
  • SortRandom -R — Randomly shuffle lines
  • SortIgnoreLeadingBlanks -b — Ignore leading blanks
  • SortStableSort -s — Stabilize sort by disabling the last-resort comparison
tail accumulate

Outputs the last N lines of input (default: 10). Supports byte-count mode and an offset mode that emits from a given line onward.

go
gloo.Run(source, tail.Tail(tail.TailLines(5)), sink)
options
  • TailLines(n) -n — Number of lines to output (default: 10)
  • TailBytes(n) -c — Number of bytes to output
  • TailFromLine(n) -n +N — Emit every line from line N onward (1-indexed)
uniq stateful-filter

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

go
gloo.Run(source, uniq.Uniq(uniq.UniqCount), sink)
options
  • UniqCount -c — Prepend occurrence counts to output lines
  • UniqDuplicatesOnly -d — Only output repeated lines
  • UniqUniqueOnly -u — Only output lines that are not repeated
  • UniqIgnoreCase -i — Case-insensitive comparison

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.

go
gloo.Run(source, awk.Awk(program, awk.AwkFieldSeparator(",")), sink)
options
  • AwkFieldSeparator(sep) -F — Input field separator (default: space)
  • AwkOutputFieldSeparator(sep) — Output field separator used when a record is rebuilt (default: space)
  • AwkVariable{Name, Value} -v — Set a variable available to the program
base64 accumulate

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

go
gloo.Run(source, base64.Base64(base64.Base64Decode), sink)
options
  • Base64Decode -d — Decode base64 input instead of encoding
  • Base64IgnoreGarbage -i — When decoding, skip non-alphabet bytes
  • Base64Wrap(cols) -w — Wrap encoded output at the given column; 0 disables wrapping (default: 76)
hexdump map

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

go
gloo.Run(source, hexdump.Hexdump(hexdump.HexdumpCanonical), sink)
options
  • HexdumpCanonical -C — 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.

go
gloo.Run(source, json.Json(), sink)
json fromcsv accumulate

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

go
gloo.Run(source, fromcsv.FromCsv(), sink)
options
  • FromCSVDelimiter(';') — CSV field delimiter (default: comma)
  • FromCSVWithoutHeader — Generate column names (col1, col2, ...) instead of reading a header row
  • FromCSVTrim — Trim leading whitespace from fields
json fromtoml aggregate

Converts TOML input to JSON output, allowing TOML documents to be processed by JSON commands.

go
gloo.Run(source, fromtoml.FromToml(), sink)
json fromtsv accumulate

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

go
gloo.Run(source, fromtsv.FromTsv(), sink)
options
  • FromTSVWithoutHeader — Generate column names (col1, col2, ...) instead of reading a header row
  • FromTSVTrim — Trim leading whitespace from fields
json fromyaml aggregate

Converts YAML input to JSON output, allowing YAML documents to be processed by JSON commands.

go
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.

go
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.

go
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.

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

Extracts the directory component of each input path.

go
gloo.Run(source, dirname.Dirname(), sink)
emit source

Returns a Source that emits the given content on stdout, with optional stderr content — useful for testing pipelines and demonstrating error handling.

go
gloo.Run(emit.Emit("hello", emit.EmitStderr("warning")), sink)
options
  • EmitStderr(content) — Also emit content on stderr
  • EmitStderrTo(w) — Direct stderr content to a specific writer
split expand

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

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

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

go
gloo.Run(source, tee.Tee(&buf), sink)
options
  • TeeAppend -a — Append to the writers instead of truncating them
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.

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

Utility

capture tap

Passes lines through unchanged while copying each one to the provided writers, useful for capturing pipeline output programmatically instead of writing to os.Stdout.

go
gloo.Run(source, capture.Capture(&buf), sink)
echo source

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

go
gloo.Run(echo.Echo("hello", "world"), sink)
exec subprocess

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

go
gloo.Run(source, exec.Exec("ls", "-la"), sink)
options
  • ExecWorkingDir(dir) — Working directory for the command
  • ExecEnvVar("KEY=value") — Set an environment variable for the command
  • ExecShell(path) — Shell to use when running through a shell
  • ExecUseShell — Execute the command through a shell
  • ExecIgnoreErrors — Continue the pipeline even if the command exits non-zero
  • ExecQuiet — Suppress the command's stderr
find source

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

go
gloo.Run(find.Find(".", find.FindName("*.go"), find.FindType("f")), sink)
options
  • FindName("*.go") -name — Glob pattern matched against entry names
  • FindType("f") -type — Filter by type: f (files) or d (directories)
  • FindMaxDepth(n) -maxdepth — Limit walk depth relative to the root
git subprocess

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

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

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

go
gloo.Run(ls.Ls(".", ls.LsAll, ls.LsRecursive), sink)
options
  • LsAll -a — Show hidden entries (starting with .)
  • LsLongFormat -l — Long format: permissions, size, and name
  • LsRecursive -R — List directory contents recursively
perl subprocess

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

go
gloo.Run(source, perl.Perl(perl.PerlScript("s/foo/bar/g"), perl.PerlPrint), sink)
options
  • PerlScript(src) -e — Perl script to run (may also be passed as the first bare string)
  • PerlLoop -n — Process input line by line
  • PerlPrint -p — Process and print each line
  • PerlAutoSplit -a — Auto-split input fields
seq source

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

go
gloo.Run(seq.Seq(1, 10), sink)
options
  • SeqEqualWidth -w — Zero-pad numbers to equal width
  • SeqSeparator(s) -s — Join all numbers with separator, emit as a single item
  • SeqFormat(fmt) -f — 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.

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

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

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