uniq

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package uniq implements the uniq builtin command.

uniq — report or omit repeated lines

Usage: uniq [OPTION]... [INPUT_FILE]

Filter adjacent matching lines from INPUT_FILE (or standard input), writing to standard output.

With no INPUT_FILE, or when INPUT_FILE is -, read standard input.

Note: the output file argument (second positional arg) supported by GNU uniq is intentionally NOT implemented because it writes to the filesystem, violating the shell's safety rules.

Accepted flags:

-c, --count
    Prefix lines by the number of occurrences.

-d, --repeated
    Only print duplicate lines, one for each group.

-D, --all-repeated[=METHOD]
    Print all duplicate lines. METHOD={none,prepend,separate}
    (default: none). Mutually exclusive with --group.

-u, --unique
    Only print unique lines (lines that are not repeated).

-i, --ignore-case
    Ignore differences in case when comparing lines.

-f N, --skip-fields=N
    Avoid comparing the first N fields. Fields are sequences of
    non-blank characters separated by blanks (spaces and tabs).

-s N, --skip-chars=N
    Avoid comparing the first N characters (applied after field
    skipping).

-w N, --check-chars=N
    Compare no more than N characters in each line.

-z, --zero-terminated
    Line delimiter is NUL (\0), not newline.

--group[=METHOD]
    Show all input lines, separating groups with an empty line.
    METHOD={separate,prepend,append,both} (default: separate).
    Mutually exclusive with -c, -d, -D, -u.

-h, --help
    Print this usage message to stdout and exit 0.

Exit codes:

0  Success.
1  An error occurred (invalid argument, missing file, incompatible flags).

Memory safety:

Lines are processed one at a time via a streaming scanner with a
per-line cap of MaxLineBytes (1 MiB). Only the current and previous
lines are kept in memory. All loops check ctx.Err() to honour the
shell's execution timeout.

Index

Constants

View Source
const MaxCount = 1<<31 - 1 // 2 147 483 647

MaxCount is the maximum accepted value for -f, -s, -w flags.

View Source
const MaxLineBytes = 1 << 20 // 1 MiB

MaxLineBytes is the per-line buffer cap for the line scanner.

Variables

View Source
var Cmd = builtins.Command{
	Name:        "uniq",
	Description: "report or omit repeated lines",
	MakeFlags:   registerFlags,
}

Cmd is the uniq builtin command descriptor.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL