]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/uniq/uniq.1
ident(1): Normalizing date format
[FreeBSD/FreeBSD.git] / usr.bin / uniq / uniq.1
1 .\" Copyright (c) 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the Institute of Electrical and Electronics Engineers, Inc.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
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.
18 .\"
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
29 .\" SUCH DAMAGE.
30 .\"
31 .\"     From: @(#)uniq.1        8.1 (Berkeley) 6/6/93
32 .\" $FreeBSD$
33 .\"
34 .Dd June 7, 2020
35 .Dt UNIQ 1
36 .Os
37 .Sh NAME
38 .Nm uniq
39 .Nd report or filter out repeated lines in a file
40 .Sh SYNOPSIS
41 .Nm
42 .Op Fl c | Fl d | Fl D | Fl u
43 .Op Fl i
44 .Op Fl f Ar num
45 .Op Fl s Ar chars
46 .Oo
47 .Ar input_file
48 .Op Ar output_file
49 .Oc
50 .Sh DESCRIPTION
51 The
52 .Nm
53 utility reads the specified
54 .Ar input_file
55 comparing adjacent lines, and writes a copy of each unique input line to
56 the
57 .Ar output_file .
58 If
59 .Ar input_file
60 is a single dash
61 .Pq Sq Fl
62 or absent, the standard input is read.
63 If
64 .Ar output_file
65 is absent, standard output is used for output.
66 The second and succeeding copies of identical adjacent input lines are
67 not written.
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.
70 .Pp
71 The following options are available:
72 .Bl -tag -width Ds
73 .It Fl c , Fl -count
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
80 .Fl d ,
81 but each copy of the repeated line is written).
82 The optional
83 .Ar septype
84 argument controls how to separate groups of repeated lines in the output;
85 it must be one of the following values:
86 .Pp
87 .Bl -tag -compact -width separate
88 .It none
89 Do not separate groups of lines (this is the default).
90 .It prepend
91 Output an empty line before each group of lines.
92 .It separate
93 Output an empty line after each group of lines.
94 .El
95 .It Fl f Ar num , Fl -skip-fields Ar num
96 Ignore the first
97 .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
100 by blanks.
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
105 Ignore the first
106 .Ar chars
107 characters in each input line when doing comparisons.
108 If specified in conjunction with the
109 .Fl f , Fl -unique
110 option, the first
111 .Ar chars
112 characters after the first
113 .Ar num
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.
118 .\".It Fl Ns Ar n
119 .\"(Deprecated; replaced by
120 .\".Fl f ) .
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
126 .\"by blanks.
127 .\".It Cm \&\(pl Ns Ar n
128 .\"(Deprecated; replaced by
129 .\".Fl s ) .
130 .\"Ignore the first
131 .\".Ar m
132 .\"characters when doing comparisons, where
133 .\".Ar m
134 .\"is a
135 .\"number.
136 .El
137 .Sh ENVIRONMENT
138 The
139 .Ev LANG ,
140 .Ev LC_ALL ,
141 .Ev LC_COLLATE
142 and
143 .Ev LC_CTYPE
144 environment variables affect the execution of
145 .Nm
146 as described in
147 .Xr environ 7 .
148 .Sh EXIT STATUS
149 .Ex -std
150 .Sh EXAMPLES
151 Assuming a file named cities.txt with the following content:
152 .Bd -literal -offset indent
153 Madrid
154 Lisbon
155 Madrid
156 .Ed
157 .Pp
158 The following command reports three different lines since identical elements
159 are not adjacent:
160 .Bd -literal -offset indent
161 $ uniq -u cities.txt
162 Madrid
163 Lisbon
164 Madrid
165 .Ed
166 .Pp
167 Sort the file and count the number of identical lines:
168 .Bd -literal -offset indent
169 $ sort cities.txt | uniq -c
170         1 Lisbon
171         2 Madrid
172 .Ed
173 .Pp
174 Assuming the following content for the file cities.txt:
175 .Bd -literal -offset indent
176 madrid
177 Madrid
178 Lisbon
179 .Ed
180 .Pp
181 Show repeated lines ignoring case sensitiveness:
182 .Bd -literal -offset indent
183 $ uniq -d -i cities.txt
184 madrid
185 .Ed
186 .Pp
187 Same as above but showing the whole group of repeated lines:
188 .Bd -literal -offset indent
189 $ uniq -D -i cities.txt
190 madrid
191 Madrid
192 .Ed
193 .Pp
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
197         2 madrid
198         1 Lisbon
199 .Ed
200 .Sh COMPATIBILITY
201 The historic
202 .Cm \&\(pl Ns Ar number
203 and
204 .Fl Ns Ar number
205 options have been deprecated but are still supported in this implementation.
206 .Sh SEE ALSO
207 .Xr sort 1
208 .Sh STANDARDS
209 The
210 .Nm
211 utility conforms to
212 .St -p1003.1-2001
213 as amended by Cor.\& 1-2002.
214 .Sh HISTORY
215 A
216 .Nm
217 command appeared in
218 .At v3 .