Commands
38 Unix commands, reimagined as type-safe streaming operations.
Text Processing
Passes lines through with optional transformations including line numbering, blank line squeezing, and non-printing character display.
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
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)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)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
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)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)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
Joins two sorted inputs on the first field, combining matching lines from both inputs.
gloo.Run(source, join.Join(join.JoinInput(input2)), sink)flags & options
--t, --separator— Field separator (default: space)
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)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)
Merges all input lines into a single output line joined by a delimiter (default: tab).
gloo.Run(source, paste.Paste(paste.PasteDelimiter(",")), sink)flags & options
--d, --delimiter— Delimiter used to join lines (default: tab)--s, --serial— Join lines serially
Reverses each input line character by character.
gloo.Run(source, rev.Rev(), sink)Applies sed expressions to each input line including substitution, deletion, printing, transliteration, and address ranges.
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
Reverses the order of input lines. Optionally splits on a custom record separator instead of newlines.
gloo.Run(source, tac.Tac(), sink)flags & options
--s, --separator— 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(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
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)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
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)flags & options
--n, --lines— Number of lines to output (default: 10)--c, --bytes— 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)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
Sorts input lines with support for reverse, numeric, unique, case-insensitive, field-based, random, and stable sorting.
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
Outputs the last N lines of input (default: 10). Supports byte-count mode for raw byte output.
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
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)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
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)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)
Encodes input to base64 (default) or decodes base64 input, with optional line wrapping for encoded output.
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)
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)flags & options
--C, --canonical— 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)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
Converts TOML input to pretty-printed JSON output, allowing TOML files 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)flags & options
---no-header, --no-header— Generate column names (col1, col2, ...) instead of reading header row---trim, --trim-spaces— Trim leading whitespace from fields
Converts YAML input to pretty-printed JSON output, allowing YAML files 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)flags & options
--s, --suffix— Suffix to strip from the basename result
Extracts the directory component of each input path.
gloo.Run(source, dirname.Dirname(), sink)Produces output on both stdout and stderr, useful for testing pipelines and demonstrating error handling.
gloo.Run(emit.Emit("hello", "warning"), sink)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)flags & options
--d, --delimiter— 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)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)flags & options
--n, --max-args— Maximum number of fields per output line (default: 1)
Utility
Captures stdin to the provided writers, useful as a pipeline sink for programmatic output capture instead of writing to os.Stdout.
gloo.Run(source, capture.Capture(&stdout, &stderr))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)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
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)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
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 and recursive traversal.
gloo.Run(ls.Ls(".", ls.LsAll, ls.LsRecursive), sink)flags & options
--a, --all— Show hidden entries (starting with .)--R, --recursive— 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("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
Returns a Source that generates a numeric sequence. Supports single endpoint, start-end, and start-step-end forms.
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
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)flags & options
--text— String to repeat (default: y)--n, --count— Limit number of repetitions (0 = infinite)