coreutils: uniq invocation
1
1 7.3 ‘uniq’: Uniquify files
1 ==========================
1
1 ‘uniq’ writes the unique lines in the given ‘input’, or standard input
1 if nothing is given or for an INPUT name of ‘-’. Synopsis:
1
1 uniq [OPTION]... [INPUT [OUTPUT]]
1
1 By default, ‘uniq’ prints its input lines, except that it discards
1 all but the first of adjacent repeated lines, so that no output lines
1 are repeated. Optionally, it can instead discard lines that are not
1 repeated, or all repeated lines.
1
1 The input need not be sorted, but repeated input lines are detected
1 only if they are adjacent. If you want to discard non-adjacent
11 duplicate lines, perhaps you want to use ‘sort -u’. ⇒sort
invocation.
1
1 Comparisons honor the rules specified by the ‘LC_COLLATE’ locale
1 category.
1
1 If no OUTPUT file is specified, ‘uniq’ writes to standard output.
1
11 The program accepts the following options. Also see ⇒Common
options.
1
1 ‘-f N’
1 ‘--skip-fields=N’
1 Skip N fields on each line before checking for uniqueness. Use a
1 null string for comparison if a line has fewer than N fields.
1 Fields are sequences of non-space non-tab characters that are
1 separated from each other by at least one space or tab.
1
1 For compatibility ‘uniq’ supports a traditional option syntax ‘-N’.
1 New scripts should use ‘-f N’ instead.
1
1 ‘-s N’
1 ‘--skip-chars=N’
1 Skip N characters before checking for uniqueness. Use a null
1 string for comparison if a line has fewer than N characters. If
1 you use both the field and character skipping options, fields are
1 skipped over first.
1
1 On systems not conforming to POSIX 1003.1-2001, ‘uniq’ supports a
1 traditional option syntax ‘+N’. Although this traditional behavior
1 can be controlled with the ‘_POSIX2_VERSION’ environment variable
1 (⇒Standards conformance), portable scripts should avoid
1 commands whose behavior depends on this variable. For example, use
1 ‘uniq ./+10’ or ‘uniq -s 10’ rather than the ambiguous ‘uniq +10’.
1
1 ‘-c’
1 ‘--count’
1 Print the number of times each line occurred along with the line.
1
1 ‘-i’
1 ‘--ignore-case’
1 Ignore differences in case when comparing lines.
1
1 ‘-d’
1 ‘--repeated’
1 Discard lines that are not repeated. When used by itself, this
1 option causes ‘uniq’ to print the first copy of each repeated line,
1 and nothing else.
1
1 ‘-D’
1 ‘--all-repeated[=DELIMIT-METHOD]’
1 Do not discard the second and subsequent repeated input lines, but
1 discard lines that are not repeated. This option is useful mainly
1 in conjunction with other options e.g., to ignore case or to
1 compare only selected fields. The optional DELIMIT-METHOD,
1 supported with the long form option, specifies how to delimit
1 groups of repeated lines, and must be one of the following:
1
1 ‘none’
1 Do not delimit groups of repeated lines. This is equivalent
1 to ‘--all-repeated’ (‘-D’).
1
1 ‘prepend’
1 Output a newline before each group of repeated lines. With
1 ‘--zero-terminated’ (‘-z’), use a zero byte (ASCII NUL)
1 instead of a newline as the delimiter.
1
1 ‘separate’
1 Separate groups of repeated lines with a single newline. This
1 is the same as using ‘prepend’, except that no delimiter is
1 inserted before the first group, and hence may be better
1 suited for output direct to users. With ‘--zero-terminated’
1 (‘-z’), use a zero byte (ASCII NUL) instead of a newline as
1 the delimiter.
1
1 Note that when groups are delimited and the input stream contains
1 blank lines, then the output is ambiguous. To avoid that, filter
1 the input through ‘tr -s '\n'’ to remove blank lines.
1
1 This is a GNU extension.
1
1 ‘--group[=DELIMIT-METHOD]’
1 Output all lines, and delimit each unique group. With
1 ‘--zero-terminated’ (‘-z’), use a zero byte (ASCII NUL) instead of
1 a newline as the delimiter. The optional DELIMIT-METHOD specifies
1 how to delimit groups, and must be one of the following:
1
1 ‘separate’
1 Separate unique groups with a single delimiter. This is the
1 default delimiting method if none is specified, and better
1 suited for output direct to users.
1
1 ‘prepend’
1 Output a delimiter before each group of unique items.
1
1 ‘append’
1 Output a delimiter after each group of unique items.
1
1 ‘both’
1 Output a delimiter around each group of unique items.
1
1 Note that when groups are delimited and the input stream contains
1 blank lines, then the output is ambiguous. To avoid that, filter
1 the input through ‘tr -s '\n'’ to remove blank lines.
1
1 This is a GNU extension.
1
1 ‘-u’
1 ‘--unique’
1 Discard the last line that would be output for a repeated input
1 group. When used by itself, this option causes ‘uniq’ to print
1 unique lines, and nothing else.
1
1 ‘-w N’
1 ‘--check-chars=N’
1 Compare at most N characters on each line (after skipping any
1 specified fields and characters). By default the entire rest of
1 the lines are compared.
1
1 ‘-z’
1 ‘--zero-terminated’
1 Delimit items with a zero byte rather than a newline (ASCII LF).
1 I.e., treat input as items separated by ASCII NUL and terminate
1 output items with ASCII NUL. This option can be useful in
1 conjunction with ‘perl -0’ or ‘find -print0’ and ‘xargs -0’ which
1 do the same in order to reliably handle arbitrary file names (even
1 those containing blanks or other special characters). Note with
1 ‘-z’ the newline character is treated as a field separator.
1
1 An exit status of zero indicates success, and a nonzero value
1 indicates failure.
1