uniq(1) User Commands uniq(1)NAMEuniq - report or filter out repeated lines in a file
SYNOPSIS
/usr/bin/uniq
/usr/bin/uniq [options] [infile [outfile]]
ksh93
uniq [options] [infile [outfile]]
DESCRIPTIONuniq 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 the output file, outfile, is not specified, uniq writes to standard
output. If no infile is given, or if the infile is -, uniq reads from
standard input with the start of the file is defined as the current
offset.
OPTIONS-c Output the number of times each line
--count occurred along with the line.
-d Output the first of each duplicate line.
--repeated | duplicates
-D Output all duplicate lines as a group with
--all-repeated[=delimit] an empty line delimiter specified by
delimit:
none Do not delimit duplicate
groups.
prepend Prepend an empty line before
each group.
separate Separate each group with an
empty line.
The option value can be omitted. The
default value is none.
-f fields is the number of fields to skip over
--skip-fields=fields before checking for uniqueness. A field is
the minimal string matching the BRE
[[:blank:]]*[^[:blank:]]*.
-i Ignore case in comparisons.
--ignore-case
-s chars is the number of characters to skip
--skip-chars=chars over before checking for uniqueness. If
specified along with -f, the first chars
after the first fields are ignored. If
chars specifies more characters than are on
the line, an empty string is used for com‐
parison.
-u Output unique lines.
--unique
-w chars is the number of characters to com‐
--check-chars=chars pare after skipping any specified fields
and characters.
-n Equivalent to -f fields with fields set to
n.
+m Equivalent to -s chars with chars set to m.
--man Prints built-in manual page in either plain
--html text, HTML or nroff format.
--nroff
--help Prints basic help information.
--version Prints version information.
OPERANDS
The following operands are supported:
infile A path name of the input file. If infile is not speci‐
fied, or if the infile is −, the standard input is used.
output_file A path name of the output file. If outfile is not speci‐
fied, the standard output is used. The results are
unspecified if the file named by outfile is the file
named by infile.
EXAMPLES
Example 1 Using the uniq Command
The following example lists the contents of the uniq.test file and out‐
puts 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(5) 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(5) for descriptions of the following attributes:
┌─────────────────────────────┬─────────────────────────────┐
│ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
├─────────────────────────────┼─────────────────────────────┤
│Availability │SUNWcs │
├─────────────────────────────┼─────────────────────────────┤
│CSI │Enabled │
├─────────────────────────────┼─────────────────────────────┤
│Interface Stability │Committed │
├─────────────────────────────┼─────────────────────────────┤
│Standard │See standards(5). │
└─────────────────────────────┴─────────────────────────────┘
SEE ALSOcomm(1), ksh93(1), pack(1), pcat(1), sort(1), uncompress(1),
attributes(5), environ(5), standards(5)SunOS 5.11 29 Nov 2009 uniq(1)