1uniq(1) User Commands uniq(1)
2
3
4
6 uniq - report or filter out repeated lines in a file
7
9 /usr/bin/uniq
10 /usr/bin/uniq [-c | -d | -u] [-f fields] [-s char]
11 [input_file [output_file]]
12
13
14 /usr/bin/uniq [-c | -d | -u] [-n] [+ m] [input_file [output_file]]
15
16
17 ksh93
18 uniq [-cdiu] [-D[delimit]] [-f fields] [-s chars] [-w chars]
19 [input_file [output_file]]
20
21
22 uniq [-cdiu] [-D[delimit]] [-n] [+m] [-w chars] [input_file [output_file]]
23
24
26 /usr/bin/uniq
27 The uniq utility reads an input file comparing adjacent lines and
28 writes one copy of each input line on the output. The second and suc‐
29 ceeding copies of repeated adjacent input lines are not written.
30
31
32 Repeated lines in the input are not detected if they are not adjacent.
33
34 ksh93
35 The uniq built-in in ksh93 is associated with the /bin or /usr/bin
36 path. It is invoked when uniq is executed without a pathname prefix and
37 the pathname search finds a /bin/uniq or /usr/bin/uniq executable.
38
39
40 uniq reads an input, comparing adjacent lines, and writing one copy of
41 each input line on the output. The second and succeeding copies of the
42 repeated adjacent lines are not written.
43
44
45 If output_file is not specified, uniq writes to standard output. If
46 input_file is not specified, or if input_file is -, uniq reads from
47 standard input, and the start of the file is defined as the current
48 offset.
49
51 /usr/bin/uniq
52 The following options are supported by /usr/bin/uniq:
53
54 -c Precedes each output line with a count of the number of
55 times the line occurred in the input.
56
57
58 -d Suppresses the writing of lines that are not repeated in
59 the input.
60
61
62 -f fields Ignores the first fields fields on each input line when
63 doing comparisons, where fields is a positive decimal
64 integer. A field is the maximal string matched by the
65 basic regular expression:
66
67 [[:blank:]]*[^[:blank:]]*
68
69
70 If fields specifies more fields than appear on an input
71 line, a null string is used for comparison.
72
73
74 +m Equivalent to -s chars with chars set to m.
75
76
77 −n Equivalent to -f fields with fields set to n.
78
79
80 -s chars Ignores the first chars characters when doing comparisons,
81 where chars is a positive decimal integer. If specified in
82 conjunction with the -f option, the first chars characters
83 after the first fields fields is ignored. If chars speci‐
84 fies more characters than remain on an input line, a null
85 string is used for comparison.
86
87
88 -u Suppresses the writing of lines that are repeated in the
89 input.
90
91
92 ksh93
93 The following options are supported by the uniq built-in command is
94 ksh93:
95
96 -c Outputs the number of times each line
97 --count occurred along with the line.
98
99
100 -d Outputs only duplicate lines.
101 --repeated | duplicates
102
103 -D Outputs all duplicate lines as a group with
104 --all-repeated[=delimit] an empty line delimiter specified by
105 delimit.
106
107 Specify delimit as one of the following:
108
109 none Do not delimit duplicate
110 groups.
111
112
113 prepend Prepend an empty line before
114 each group.
115
116
117 separate Separate each group with an
118 empty line.
119
120 The value for delimit can be omitted. The
121 default value is none.
122
123
124 -f Skips over fields number of fields before
125 --skip-fields=fields checking for uniqueness. A field is the
126 minimal string matching the BRE
127 [[:blank:]]*[^[:blank:]]*.
128
129
130 -i Ignore case in comparisons.
131 --ignore-case
132
133 +m Equivalent to the -s chars option, with
134 chars set to m.
135
136
137 -n Equivalent to the -f fields option, with
138 fields set to n.
139
140
141 -s Skips over chars number of characters
142 --skip-chars=chars before checking for uniqueness.
143
144 If specified with the -f option, the first
145 chars after the first fields are ignored.
146 If the chars specifies more characters than
147 are on the line, an empty string is used
148 for comparison.
149
150
151 -u Outputs unique lines.
152 --uniq
153
154 -w Skips over any specified fields and charac‐
155 --check-chars=chars ters, then compares chars number of charac‐
156 ters.
157
158
160 The following operands are supported:
161
162 input_file A path name of the input file. If input_file is not
163 specified, or if the input_file is −, the standard input
164 is used.
165
166
167 output_file A path name of the output file. If output_file is not
168 specified, the standard output is used. The results are
169 unspecified if the file named by output_file is the file
170 named by input_file.
171
172
174 Example 1 Using the uniq Command
175
176
177 The following example lists the contents of the uniq.test file and out‐
178 puts a copy of the repeated lines.
179
180
181 example% cat uniq.test
182 This is a test.
183 This is a test.
184 TEST.
185 Computer.
186 TEST.
187 TEST.
188 Software.
189
190 example% uniq -d uniq.test
191 This is a test.
192 TEST.
193 example%
194
195
196
197
198 The next example outputs just those lines that are not repeated in the
199 uniq.test file.
200
201
202 example% uniq -u uniq.test
203 TEST.
204 Computer.
205 Software.
206 example%
207
208
209
210
211 The last example outputs a report with each line preceded by a count of
212 the number of times each line occurred in the file:
213
214
215 example% uniq -c uniq.test
216 2 This is a test.
217 1 TEST.
218 1 Computer.
219 2 TEST.
220 1 Software.
221 example%
222
223
224
226 See environ(5) for descriptions of the following environment variables
227 that affect the execution of uniq: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES,
228 and NLSPATH.
229
231 The following exit values are returned:
232
233 0 Successful completion.
234
235
236 >0 An error occurred.
237
238
240 See attributes(5) for descriptions of the following attributes:
241
242 /usr/bin/uniq
243 ┌─────────────────────────────┬─────────────────────────────┐
244 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
245 ├─────────────────────────────┼─────────────────────────────┤
246 │Availability │SUNWesu │
247 ├─────────────────────────────┼─────────────────────────────┤
248 │CSI │Enabled │
249 ├─────────────────────────────┼─────────────────────────────┤
250 │Interface Stability │Committed │
251 ├─────────────────────────────┼─────────────────────────────┤
252 │Standard │See standards(5). │
253 └─────────────────────────────┴─────────────────────────────┘
254
255 ksh93
256 ┌─────────────────────────────┬─────────────────────────────┐
257 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
258 ├─────────────────────────────┼─────────────────────────────┤
259 │Availability │SUNWcsu │
260 ├─────────────────────────────┼─────────────────────────────┤
261 │Interface Stability │See below. │
262 └─────────────────────────────┴─────────────────────────────┘
263
264
265 The ksh93 built-in binding to /bin and /usr/bin is Volatile. The built-
266 in interfaces are Uncommitted.
267
269 comm(1), ksh93(1), , pcat(1), sort(1), uncompress(1), attributes(5),
270 environ(5), standards(5)
271
272
273
274SunOS 5.11 13 Mar 2008 uniq(1)