xref: /illumos-gate/usr/src/man/man1/uniq.1 (revision bbf21555)

Sun Microsystems, Inc. gratefully acknowledges The Open Group for
permission to reproduce portions of its copyrighted documentation.
Original documentation from The Open Group can be obtained online at
http://www.opengroup.org/bookstore/.

The Institute of Electrical and Electronics Engineers and The Open
Group, have given us permission to reprint portions of their
documentation.

In the following statement, the phrase ``this text'' refers to portions
of the system documentation.

Portions of this text are reprinted and reproduced in electronic form
in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
Standard for Information Technology -- Portable Operating System
Interface (POSIX), The Open Group Base Specifications Issue 6,
Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
Engineers, Inc and The Open Group. In the event of any discrepancy
between these versions and the original IEEE and The Open Group
Standard, the original IEEE and The Open Group Standard is the referee
document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html.

This notice shall appear on any product containing this material.

The contents of this file are subject to the terms of the
Common Development and Distribution License (the "License").
You may not use this file except in compliance with the License.

You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
or http://www.opensolaris.org/os/licensing.
See the License for the specific language governing permissions
and limitations under the License.

When distributing Covered Code, include this CDDL HEADER in each
file and include the License file at usr/src/OPENSOLARIS.LICENSE.
If applicable, add the following below this CDDL HEADER, with the
fields enclosed by brackets "[]" replaced with your own identifying
information: Portions Copyright [yyyy] [name of copyright owner]


Copyright 1989 AT&T
Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved

UNIQ 1 "May 23, 2021"
NAME
uniq - report or filter out repeated lines in a file
SYNOPSIS
/usr/bin/uniq [-c | -d | -u] [-f fields] [-s char]
 [input_file [output_file]]

/usr/bin/uniq [-c | -d | -u] [-n] [+ m] [input_file [output_file]]
"ksh93"
uniq [-cdiu] [-D[delimit]] [-f fields] [-s chars] [-w chars]
 [input_file [output_file]]

uniq [-cdiu] [-D[delimit]] [-n] [+m] [-w chars] [input_file [output_file]]
DESCRIPTION
The uniq utility reads an input file comparing adjacent lines and writes one copy of each input line on the output. The second and succeeding copies of repeated adjacent input lines are not written.

Repeated lines in the input are not detected if they are not adjacent.

"ksh93"
The uniq built-in in ksh93 is associated with the /bin or /usr/bin path. It is invoked when uniq is executed without a pathname prefix and the pathname search finds a /bin/uniq or /usr/bin/uniq executable.

uniq reads an input, comparing adjacent lines, and writing one copy of each input line on the output. The second and succeeding copies of the repeated adjacent lines are not written.

If output_file is not specified, uniq writes to standard output. If input_file is not specified, or if input_file is -, uniq reads from standard input, and the start of the file is defined as the current offset.

OPTIONS
The following options are supported by /usr/bin/uniq: -c

Precedes each output line with a count of the number of times the line occurred in the input.

-d

Suppresses the writing of lines that are not repeated in the input.

-f fields

Ignores the first fields fields on each input line when doing comparisons, where fields is a positive decimal integer. A field is the maximal string matched by the basic regular expression:

[[:blank:]]*[^[:blank:]]*
If fields specifies more fields than appear on an input line, a null string is used for comparison.
+m

Equivalent to -s chars with chars set to m.

-n

Equivalent to -f fields with fields set to n.

-s chars

Ignores the first chars characters when doing comparisons, where chars is a positive decimal integer. If specified in conjunction with the -f option, the first chars characters after the first fields fields is ignored. If chars specifies more characters than remain on an input line, a null string is used for comparison.

-u

Suppresses the writing of lines that are repeated in the input.

"ksh93"
The following options are supported by the uniq built-in command is ksh93: -c

--count

Outputs the number of times each line occurred along with the line.

-d

--repeated | duplicates

Outputs only duplicate lines.

-D

--all-repeated[=delimit]

Outputs all duplicate lines as a group with an empty line delimiter specified by delimit. Specify delimit as one of the following: none

Do not delimit duplicate groups.

prepend

Prepend an empty line before each group.

separate

Separate each group with an empty line.

The value for delimit can be omitted. The default value is none.
-f

--skip-fields=fields

Skips over fields number of fields before checking for uniqueness. A field is the minimal string matching the BRE [[:blank:]]*[^[:blank:]]*.

-i

--ignore-case

Ignore case in comparisons.

+m

Equivalent to the -s chars option, with chars set to m.

-n

Equivalent to the -f fields option, with fields set to n.

-s

--skip-chars=chars

Skips over chars number of characters before checking for uniqueness. If specified with the -f option, the first chars after the first fields are ignored. If the chars specifies more characters than are on the line, an empty string is used for comparison.

-u

--uniq

Outputs unique lines.

-w

--check-chars=chars

Skips over any specified fields and characters, then compares chars number of characters.

OPERANDS
The following operands are supported: input_file

A path name of the input file. If input_file is not specified, or if the input_file is -, the standard input is used.

output_file

A path name of the output file. If output_file is not specified, the standard output is used. The results are unspecified if the file named by output_file is the file named by input_file.

EXAMPLES
Example 1 Using the uniq Command

The following example lists the contents of the uniq.test file and outputs a copy of the repeated lines.

example% cat uniq.test
This is a test.
This is a test.
TEST.
Computer.
TEST.
TEST.
Software.

example% uniq -d uniq.test
This is a test.
TEST.
example%

The next example outputs just those lines that are not repeated in the uniq.test file.

example% uniq -u uniq.test
TEST.
Computer.
Software.
example%

The last example outputs a report with each line preceded by a count of the number of times each line occurred in the file:

example% uniq -c uniq.test
 2 This is a test.
 1 TEST.
 1 Computer.
 2 TEST.
 1 Software.
example%
ENVIRONMENT VARIABLES
See environ(7) for descriptions of the following environment variables that affect the execution of uniq: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH.
EXIT STATUS
The following exit values are returned: 0

Successful completion.

>0

An error occurred.

ATTRIBUTES
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE ATTRIBUTE VALUE
CSI Enabled
Interface Stability Committed
Standard See standards(7).
"ksh93"
ATTRIBUTE TYPE ATTRIBUTE VALUE
Interface Stability See below.

The ksh93 built-in binding to /bin and /usr/bin is Volatile. The built-in interfaces are Uncommitted.

SEE ALSO
comm (1), ksh93 (1), sort (1), attributes (7), environ (7), standards (7)