Commands
44 Unix commands, reimagined as type-safe streaming operations.
Text Processing
Passes lines through unchanged, optionally numbering every line or only the non-blank lines.
gloo.Run(source, cat.Cat(cat.CatNumberLines), sink)options
CatNumberLines-n — Number all output linesCatNumberNonBlank-b — Number non-blank output lines only (overrides -n)
Compares two sorted inputs line by line, outputting three columns: lines only in first input, lines only in second input, and lines in both.
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
Selects fields, bytes, or characters from each input line by position, equivalent to the Unix cut utility.
gloo.Run(source, cut.Cut(cut.CutFields(1, 3), cut.CutDelimiter(",")), sink)options
CutFields(1, 3)-f — Select fields by 1-based positionCutDelimiter(d)-d — Field delimiter (default: tab)CutBytes("1-3,5")-b — Select bytes by position rangeCutChars("1-3,5")-c — Select characters (runes) by position rangeCutComplement--complement — Invert the selection for any mode
Computes a simple line diff between stdin and a second input, reporting lines that differ with < and > prefixes.
gloo.Run(source, diff.Diff(diff.DiffInput(input2)), sink)options
DiffUnified-u — Output a unified diff instead of the default ed-style diffDiffInput(lines)— Supply the second input as raw lines
Filters lines containing the given pattern with support for regex, case-insensitive, inverted, word, and whole-line matching.
gloo.Run(source, grep.Grep("ERROR", grep.GrepIgnoreCase), sink)options
GrepIgnoreCase-i — Case-insensitive matchingGrepInvert-v — Invert match (print non-matching lines)GrepWholeLine-x — Match only if entire line equals patternGrepExtended-E — Interpret pattern as extended regexGrepWord-w — Match pattern only at word boundariesGrepLineNumbers-n — Prepend line number to each matching lineGrepCount-c — Count matching lines instead of printing them
Joins two sorted inputs on the first field, combining matching lines from both inputs.
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
Numbers lines from input with configurable body numbering, separator, start value, increment, width, and format.
gloo.Run(source, nl.Nl(nl.NlStart(1), nl.NlWidth(4)), sink)options
NlBodyAll-b — Which lines to number: NlBodyAll, NlBodyNonEmpty, or NlBodyNoneNlSep(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)
Merges all input lines into a single output line joined by a delimiter (default: tab).
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
Reverses each input line character by character.
gloo.Run(source, rev.Rev(), sink)Applies a single sed expression to each input line, supporting substitution, deletion, printing, transliteration, and address ranges.
gloo.Run(source, sed.Sed("s/old/new/g"), sink)Reverses the order of input lines. Optionally splits on a custom record separator instead of newlines.
gloo.Run(source, tac.Tac(), sink)options
TacSep(s)-s — Split on a custom record separator instead of newlines
Translates, deletes, or squeezes characters using character set mappings with support for ranges like a-z.
gloo.Run(source, tr.Tr("a-z", "A-Z"), sink)options
TrDelete-d — Delete characters in set1 from inputTrSqueeze-s — Squeeze runs of repeated characters to a single characterTrComplement-c — Use the complement of set1
Counts lines, words, and bytes from the input stream. With no flags, all three counts are shown space-separated.
gloo.Run(source, wc.Wc(wc.WcLines), sink)options
WcLines-l — Count linesWcWords-w — Count wordsWcBytes-c — Count bytesWcChars-m — Count characters (runes)WcMaxLineLength-L — Report the maximum line length in bytes
Stream Selection
Outputs the first N lines of input (default: 10). Supports byte-count mode for raw byte output.
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
Randomly shuffles input lines with optional count limit, deterministic seed, integer range generation, and echo mode.
gloo.Run(source, shuf.Shuf(shuf.ShufCount(5)), sink)options
ShufCount(n)-n — Limit output to N linesShufSeed(n)— Random seed for deterministic outputShufRange(lo, hi)-i — Generate and shuffle integers from lo to hiShufEcho(args...)-e — Shuffle the given arguments instead of stdin
Sorts input lines with support for reverse, numeric, human-numeric, month, version, unique, case-insensitive, field-based, random, and stable sorting.
gloo.Run(source, sort.Sort(sort.SortReverse, sort.SortNumeric), sink)options
SortReverse-r — Reverse sort orderSortNumeric-n — Compare according to numeric valueSortHumanNumeric-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 linesSortIgnoreCase-f — Case-insensitive comparisonSortField(n)-k — Sort by field position (1-based)SortDelimiter(d)-t — Field delimiter (default: whitespace)SortRandom-R — Randomly shuffle linesSortIgnoreLeadingBlanks-b — Ignore leading blanksSortStableSort-s — Stabilize sort by disabling the last-resort comparison
Outputs the last N lines of input (default: 10). Supports byte-count mode and an offset mode that emits from a given line onward.
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 outputTailFromLine(n)-n +N — Emit every line from line N onward (1-indexed)
Filters adjacent duplicate lines from input with support for counting, duplicate-only, unique-only, and case-insensitive comparison.
gloo.Run(source, uniq.Uniq(uniq.UniqCount), sink)options
UniqCount-c — Prepend occurrence counts to output linesUniqDuplicatesOnly-d — Only output repeated linesUniqUniqueOnly-u — Only output lines that are not repeatedUniqIgnoreCase-i — Case-insensitive comparison
Data Transformation
Processes input lines through an awk-style program with Begin, Condition, Action, and End phases, supporting field splitting and variables.
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
Encodes input to base64 (default) or decodes base64 input, with optional line wrapping for encoded output.
gloo.Run(source, base64.Base64(base64.Base64Decode), sink)options
Base64Decode-d — Decode base64 input instead of encodingBase64IgnoreGarbage-i — When decoding, skip non-alphabet bytesBase64Wrap(cols)-w — Wrap encoded output at the given column; 0 disables wrapping (default: 76)
Formats input as a hex dump with running byte offsets and optional canonical mode showing ASCII printable characters.
gloo.Run(source, hexdump.Hexdump(hexdump.HexdumpCanonical), sink)options
HexdumpCanonical-C — Canonical hex+ASCII display
Parses each input line as JSON and re-emits it in compact form. Each input line must be valid JSON.
gloo.Run(source, json.Json(), sink)Converts CSV input to newline-delimited JSON output, using the header row as object keys for each subsequent row.
gloo.Run(source, fromcsv.FromCsv(), sink)options
FromCSVDelimiter(';')— CSV field delimiter (default: comma)FromCSVWithoutHeader— Generate column names (col1, col2, ...) instead of reading a header rowFromCSVTrim— Trim leading whitespace from fields
Converts TOML input to JSON output, allowing TOML documents to be processed by JSON commands.
gloo.Run(source, fromtoml.FromToml(), sink)Converts TSV (tab-separated values) input to newline-delimited JSON output, using the header row as object keys.
gloo.Run(source, fromtsv.FromTsv(), sink)options
FromTSVWithoutHeader— Generate column names (col1, col2, ...) instead of reading a header rowFromTSVTrim— Trim leading whitespace from fields
Converts YAML input to JSON output, allowing YAML documents to be processed by JSON commands.
gloo.Run(source, fromyaml.FromYaml(), sink)Extracts specified fields from JSON objects, emitting only the selected fields as a new JSON object.
gloo.Run(source, pluck.Pluck("name", "age"), sink)Filters JSON values based on a condition function, with built-in condition builders for field existence, equality, and predicate matching.
gloo.Run(source, selectcmd.Select(selectcmd.HasField("name")), sink)File / Line Operations
Extracts the filename component of each input path with optional suffix stripping.
gloo.Run(source, basename.Basename(basename.BasenameSuffix(".go")), sink)options
BasenameSuffix(suffix)-s — Suffix to strip from the basename result
Extracts the directory component of each input path.
gloo.Run(source, dirname.Dirname(), sink)Returns a Source that emits the given content on stdout, with optional stderr content — useful for testing pipelines and demonstrating error handling.
gloo.Run(emit.Emit("hello", emit.EmitStderr("warning")), sink)options
EmitStderr(content)— Also emit content on stderrEmitStderrTo(w)— Direct stderr content to a specific writer
Splits each input line on a delimiter into multiple output lines. With no options, splits on whitespace.
gloo.Run(source, split.Split(split.SplitDelim(",")), sink)options
SplitDelim(",")-d — Field delimiter for splitting (default: whitespace)
Passes lines through unchanged while writing each line to the provided writers as a side effect.
gloo.Run(source, tee.Tee(&buf), sink)options
TeeAppend-a — Append to the writers instead of truncating them
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.
gloo.Run(source, xargs.Xargs(xargs.XargsMaxArgs(3)), sink)options
XargsMaxArgs(n)-n — Maximum number of fields per output line (default: 1)
Utility
Passes lines through unchanged while copying each one to the provided writers, useful for capturing pipeline output programmatically instead of writing to os.Stdout.
gloo.Run(source, capture.Capture(&buf), sink)Returns a Source that emits its arguments joined by spaces as a single line.
gloo.Run(echo.Echo("hello", "world"), sink)Forks an external command with the given arguments, wiring stdin/stdout/stderr to the pipeline.
gloo.Run(source, exec.Exec("ls", "-la"), sink)options
ExecWorkingDir(dir)— Working directory for the commandExecEnvVar("KEY=value")— Set an environment variable for the commandExecShell(path)— Shell to use when running through a shellExecUseShell— Execute the command through a shellExecIgnoreErrors— Continue the pipeline even if the command exits non-zeroExecQuiet— Suppress the command's stderr
Returns a Source that walks a directory tree and emits matching paths with optional name glob, type filter, and depth limit.
gloo.Run(find.Find(".", find.FindName("*.go"), find.FindType("f")), sink)options
FindName("*.go")-name — Glob pattern matched against entry namesFindType("f")-type — Filter by type: f (files) or d (directories)FindMaxDepth(n)-maxdepth — Limit walk depth relative to the root
Forks git with the given subcommand and arguments, wiring the pipeline stream through the git process.
gloo.Run(source, git.Git("log", "--oneline"), sink)Returns a Source that lists directory entries with optional hidden-file display, long format, and recursive traversal.
gloo.Run(ls.Ls(".", ls.LsAll, ls.LsRecursive), sink)options
LsAll-a — Show hidden entries (starting with .)LsLongFormat-l — Long format: permissions, size, and nameLsRecursive-R — List directory contents recursively
Forks perl with a script, supporting loop mode, print mode, and auto-split mode for one-liner text processing.
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 linePerlPrint-p — Process and print each linePerlAutoSplit-a — Auto-split input fields
Returns a Source that generates a numeric sequence. Supports single endpoint, start-end, and start-step-end forms passed as positional numbers.
gloo.Run(seq.Seq(1, 10), sink)options
SeqEqualWidth-w — Zero-pad numbers to equal widthSeqSeparator(s)-s — Join all numbers with separator, emit as a single itemSeqFormat(fmt)-f — Printf-style format string for each number
Executes a body function for each input line, emitting the results as a general-purpose per-line transformation.
gloo.Run(source, while.While(func(line []byte) ([]byte, error) { return line, nil }), sink)Returns a Source that emits a string repeatedly until context is cancelled. Default string is y.
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)