1 .\" Copyright (c) 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the Institute of Electrical and Electronics Engineers, Inc.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" From: @(#)uniq.1 8.1 (Berkeley) 6/6/93
39 .Nd report or filter out repeated lines in a file
42 .Op Fl c | Fl d | Fl D | Fl u
53 utility reads the specified
55 comparing adjacent lines, and writes a copy of each unique input line to
62 or absent, the standard input is read.
65 is absent, standard output is used for output.
66 The second and succeeding copies of identical adjacent input lines are
68 Repeated lines in the input will not be detected if they are not adjacent,
69 so it may be necessary to sort the files first.
71 The following options are available:
74 Precede each output line with the count of the number of times the line
75 occurred in the input, followed by a single space.
76 .It Fl d , Fl -repeated
77 Output a single copy of each line that is repeated in the input.
78 .It Fl D , Fl -all-repeated Op Ar septype
79 Output all lines that are repeated (like
81 but each copy of the repeated line is written).
84 argument controls how to separate groups of repeated lines in the output;
85 it must be one of the following values:
87 .Bl -tag -compact -width separate
89 Do not separate groups of lines (this is the default).
91 Output an empty line before each group of lines.
93 Output an empty line after each group of lines.
95 .It Fl f Ar num , Fl -skip-fields Ar num
98 fields in each input line when doing comparisons.
99 A field is a string of non-blank characters separated from adjacent fields
101 Field numbers are one based, i.e., the first field is field one.
102 .It Fl i , Fl -ignore-case
103 Case insensitive comparison of lines.
104 .It Fl s Ar chars , Fl -skip-chars Ar chars
107 characters in each input line when doing comparisons.
108 If specified in conjunction with the
112 characters after the first
114 fields will be ignored.
115 Character numbers are one based, i.e., the first character is character one.
116 .It Fl u , Fl -unique
117 Only output lines that are not repeated in the input.
119 .\"(Deprecated; replaced by
121 .\"Ignore the first n
122 .\"fields on each input line when doing comparisons,
123 .\"where n is a number.
124 .\"A field is a string of non-blank
125 .\"characters separated from adjacent fields
127 .\".It Cm \&\(pl Ns Ar n
128 .\"(Deprecated; replaced by
132 .\"characters when doing comparisons, where
144 environment variables affect the execution of
151 Assuming a file named cities.txt with the following content:
152 .Bd -literal -offset indent
158 The following command reports three different lines since identical elements
160 .Bd -literal -offset indent
167 Sort the file and count the number of identical lines:
168 .Bd -literal -offset indent
169 $ sort cities.txt | uniq -c
174 Assuming the following content for the file cities.txt:
175 .Bd -literal -offset indent
181 Show repeated lines ignoring case sensitiveness:
182 .Bd -literal -offset indent
183 $ uniq -d -i cities.txt
187 Same as above but showing the whole group of repeated lines:
188 .Bd -literal -offset indent
189 $ uniq -D -i cities.txt
194 Report the number of identical lines ignoring the first character of every line:
195 .Bd -literal -offset indent
196 $ uniq -s 1 -c cities.txt
202 .Cm \&\(pl Ns Ar number
205 options have been deprecated but are still supported in this implementation.
213 as amended by Cor.\& 1-2002.