Print this page
3737 grep does not support -H option
3759 egrep(1) and fgrep(1) -s flag does not hide -c output
Reviewed by: Albert Lee <trisk@nexenta.com>
Reviewed by: Andy Stormont <andyjstormont@gmail.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/man/man1/grep.1
+++ new/usr/src/man/man1/grep.1
1 1 '\" te
2 2 .\" Copyright 2012 Nexenta Systems, Inc. All rights reserved.
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
3 3 .\" Copyright 1989 AT&T
4 4 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
5 5 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
6 6 .\" 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
7 7 .\" http://www.opengroup.org/bookstore/.
8 8 .\" 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 Sun OS 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.
9 9 .\" This notice shall appear on any product containing this material.
10 10 .\" 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.
11 11 .\" 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.
12 12 .\" 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]
13 -.TH GREP 1 "Feb 26, 2008"
13 +.TH GREP 1 "May 3, 2013"
14 14 .SH NAME
15 15 grep \- search a file for a pattern
16 16 .SH SYNOPSIS
17 17 .LP
18 18 .nf
19 -\fB/usr/bin/grep\fR [\fB-c\fR | \fB-l\fR |\fB-q\fR] [\fB-r\fR | \fB-R\fR] [\fB-bhinsvw\fR]
19 +\fB/usr/bin/grep\fR [\fB-c\fR | \fB-l\fR |\fB-q\fR] [\fB-r\fR | \fB-R\fR] [\fB-bHhinsvw\fR]
20 20 \fIlimited-regular-expression\fR [\fIfilename\fR]...
21 21 .fi
22 22
23 23 .LP
24 24 .nf
25 25 \fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-r\fR | \fB-R\fR]
26 - [\fB-bhinsvwx\fR] \fB-e\fR \fIpattern_list\fR... [\fB-f\fR \fIpattern_file\fR]...
26 + [\fB-bHhinsvwx\fR] \fB-e\fR \fIpattern_list\fR... [\fB-f\fR \fIpattern_file\fR]...
27 27 [\fIfile\fR]...
28 28 .fi
29 29
30 30 .LP
31 31 .nf
32 32 \fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-r\fR | \fB-R\fR]
33 - [\fB-bhinsvwx\fR] [\fB-e\fR \fIpattern_list\fR]... \fB-f\fR \fIpattern_file\fR...
33 + [\fB-bHhinsvwx\fR] [\fB-e\fR \fIpattern_list\fR]... \fB-f\fR \fIpattern_file\fR...
34 34 [\fIfile\fR]...
35 35 .fi
36 36
37 37 .LP
38 38 .nf
39 39 \fB/usr/xpg4/bin/grep\fR [\fB-E\fR | \fB-F\fR] [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-r\fR | \fB-R\fR]
40 - [\fB-bhinsvwx\fR] \fIpattern\fR [\fIfile\fR]...
40 + [\fB-bHhinsvwx\fR] \fIpattern\fR [\fIfile\fR]...
41 41 .fi
42 42
43 43 .SH DESCRIPTION
44 44 .sp
45 45 .LP
46 46 The \fBgrep\fR utility searches text files for a pattern and prints all lines
47 47 that contain that pattern. It uses a compact non-deterministic algorithm.
48 48 .sp
49 49 .LP
50 50 Be careful using the characters \fB$\fR, \fB*\fR, \fB[\fR, \fB^\fR, \fB|\fR,
51 51 \fB(\fR, \fB)\fR, and \fB\e\fR in the \fIpattern_list\fR because they are also
52 52 meaningful to the shell. It is safest to enclose the entire \fIpattern_list\fR
53 53 in single quotes \fBa\'\fR\&...\fBa\'\fR\&.
54 54 .sp
55 55 .LP
56 56 If no files are specified, \fBgrep\fR assumes standard input. Normally, each
57 57 line found is copied to standard output. The file name is printed before each
58 58 line found if there is more than one input file.
59 59 .SS "/usr/bin/grep"
60 60 .sp
61 61 .LP
62 62 The \fB/usr/bin/grep\fR utility uses limited regular expressions like those
63 63 described on the \fBregexp\fR(5) manual page to match the patterns.
64 64 .SS "/usr/xpg4/bin/grep"
65 65 .sp
66 66 .LP
67 67 The options \fB-E\fR and \fB-F\fR affect the way \fB/usr/xpg4/bin/grep\fR
68 68 interprets \fIpattern_list\fR. If \fB-E\fR is specified,
69 69 \fB/usr/xpg4/bin/grep\fR interprets \fIpattern_list\fR as a full regular
70 70 expression (see \fB-E\fR for description). If \fB-F\fR is specified,
71 71 \fBgrep\fR interprets \fIpattern_list\fR as a fixed string. If neither are
72 72 specified, \fBgrep\fR interprets \fIpattern_list\fR as a basic regular
73 73 expression as described on \fBregex\fR(5) manual page.
74 74 .SH OPTIONS
75 75 .sp
76 76 .LP
77 77 The following options are supported for both \fB/usr/bin/grep\fR and
78 78 \fB/usr/xpg4/bin/grep\fR:
79 79 .sp
80 80 .ne 2
81 81 .na
82 82 \fB\fB-b\fR\fR
83 83 .ad
84 84 .RS 6n
85 85 Precedes each line by the block number on which it was found. This can be
86 86 useful in locating block numbers by context (first block is 0).
87 87 .RE
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
88 88
89 89 .sp
90 90 .ne 2
91 91 .na
92 92 \fB\fB-c\fR\fR
93 93 .ad
94 94 .RS 6n
95 95 Prints only a count of the lines that contain the pattern.
96 96 .RE
97 97
98 +.sp
99 +.ne 2
100 +.na
101 +\fB\fB-H\fR\fR
102 +.ad
103 +.RS 6n
104 +Precedes each line by the name of the file containing the matching line.
105 +.RE
106 +
98 107 .sp
99 108 .ne 2
100 109 .na
101 110 \fB\fB-h\fR\fR
102 111 .ad
103 112 .RS 6n
104 113 Prevents the name of the file containing the matching line from being prepended
105 114 to that line. Used when searching multiple files.
106 115 .RE
107 116
108 117 .sp
109 118 .ne 2
110 119 .na
111 120 \fB\fB-i\fR\fR
112 121 .ad
113 122 .RS 6n
114 123 Ignores upper/lower case distinction during comparisons.
115 124 .RE
116 125
117 126 .sp
118 127 .ne 2
119 128 .na
120 129 \fB\fB-l\fR\fR
121 130 .ad
122 131 .RS 6n
123 132 Prints only the names of files with matching lines, separated by NEWLINE
124 133 characters. Does not repeat the names of files when the pattern is found more
125 134 than once.
126 135 .RE
127 136
128 137 .sp
129 138 .ne 2
130 139 .na
131 140 \fB\fB-n\fR\fR
132 141 .ad
133 142 .RS 6n
134 143 Precedes each line by its line number in the file (first line is 1).
135 144 .RE
136 145
137 146 .sp
138 147 .ne 2
139 148 .na
140 149 \fB\fB-r\fR\fR
141 150 .ad
142 151 .RS 6n
143 152 Read all files under each directory, recursively. Follow symbolic links on
144 153 the command line, but skip symlinks that are encountered recursively. If file
145 154 is a device, FIFO, or socket, skip it.
146 155 .RE
147 156
148 157 .sp
149 158 .ne 2
150 159 .na
151 160 \fB\fB-R\fR\fR
152 161 .ad
153 162 .RS 6n
154 163 Read all files under each directory, recursively, following all symbolic links.
155 164 .RE
156 165
157 166 .sp
158 167 .ne 2
159 168 .na
160 169 \fB\fB-q\fR\fR
161 170 .ad
162 171 .RS 6n
163 172 Quiet. Does not write anything to the standard output, regardless of matching
164 173 lines. Exits with zero status if an input line is selected.
165 174 .RE
166 175
167 176 .sp
168 177 .ne 2
169 178 .na
170 179 \fB\fB-s\fR\fR
171 180 .ad
172 181 .RS 6n
173 182 Suppresses error messages about nonexistent or unreadable files.
174 183 .RE
175 184
176 185 .sp
177 186 .ne 2
178 187 .na
179 188 \fB\fB-v\fR\fR
180 189 .ad
181 190 .RS 6n
182 191 Prints all lines except those that contain the pattern.
183 192 .RE
184 193
185 194 .sp
186 195 .ne 2
187 196 .na
188 197 \fB\fB-w\fR\fR
189 198 .ad
190 199 .RS 6n
191 200 Searches for the expression as a word as if surrounded by \fB\e<\fR and
192 201 \fB\e>\fR\&.
193 202 .RE
194 203
195 204 .SS "/usr/xpg4/bin/grep"
196 205 .sp
197 206 .LP
198 207 The following options are supported for \fB/usr/xpg4/bin/grep\fR only:
199 208 .sp
200 209 .ne 2
201 210 .na
202 211 \fB\fB-e\fR \fIpattern_list\fR\fR
203 212 .ad
204 213 .RS 19n
205 214 Specifies one or more patterns to be used during the search for input. Patterns
206 215 in \fIpattern_list\fR must be separated by a NEWLINE character. A null pattern
207 216 can be specified by two adjacent newline characters in \fIpattern_list\fR.
208 217 Unless the \fB-E\fR or \fB-F\fR option is also specified, each pattern is
209 218 treated as a basic regular expression. Multiple \fB-e\fR and \fB-f\fR options
210 219 are accepted by \fBgrep\fR. All of the specified patterns are used when
211 220 matching lines, but the order of evaluation is unspecified.
212 221 .RE
213 222
214 223 .sp
215 224 .ne 2
216 225 .na
217 226 \fB\fB-E\fR\fR
218 227 .ad
219 228 .RS 19n
220 229 Matches using full regular expressions. Treats each pattern specified as a full
221 230 regular expression. If any entire full regular expression pattern matches an
222 231 input line, the line is matched. A null full regular expression matches every
223 232 line. Each pattern is interpreted as a full regular expression as described on
224 233 the \fBregex\fR(5) manual page, except for \fB\e(\fR and \fB\e)\fR, and
225 234 including:
226 235 .RS +4
227 236 .TP
228 237 1.
229 238 A full regular expression followed by \fB+\fR that matches one or more
230 239 occurrences of the full regular expression.
231 240 .RE
232 241 .RS +4
233 242 .TP
234 243 2.
235 244 A full regular expression followed by \fB?\fR that matches 0 or 1
236 245 occurrences of the full regular expression.
237 246 .RE
238 247 .RS +4
239 248 .TP
240 249 3.
241 250 Full regular expressions separated by | or by a new-line that match strings
242 251 that are matched by any of the expressions.
243 252 .RE
244 253 .RS +4
245 254 .TP
246 255 4.
247 256 A full regular expression that is enclosed in parentheses \fB()\fR for
248 257 grouping.
249 258 .RE
250 259 The order of precedence of operators is \fB[\|]\fR, then \fB*\|?\|+\fR, then
251 260 concatenation, then | and new-line.
252 261 .RE
253 262
254 263 .sp
255 264 .ne 2
256 265 .na
257 266 \fB\fB-f\fR \fIpattern_file\fR\fR
258 267 .ad
259 268 .RS 19n
260 269 Reads one or more patterns from the file named by the path name
261 270 \fIpattern_file\fR. Patterns in \fIpattern_file\fR are terminated by a NEWLINE
262 271 character. A null pattern can be specified by an empty line in
263 272 \fIpattern_file\fR. Unless the \fB-E\fR or \fB-F\fR option is also specified,
264 273 each pattern is treated as a basic regular expression.
265 274 .RE
266 275
267 276 .sp
268 277 .ne 2
269 278 .na
270 279 \fB\fB-F\fR\fR
271 280 .ad
272 281 .RS 19n
273 282 Matches using fixed strings. Treats each pattern specified as a string instead
274 283 of a regular expression. If an input line contains any of the patterns as a
275 284 contiguous sequence of bytes, the line is matched. A null string matches every
276 285 line. See \fBfgrep\fR(1) for more information.
277 286 .RE
278 287
279 288 .sp
280 289 .ne 2
281 290 .na
282 291 \fB\fB-x\fR\fR
283 292 .ad
284 293 .RS 19n
285 294 Considers only input lines that use all characters in the line to match an
286 295 entire fixed string or regular expression to be matching lines.
287 296 .RE
288 297
289 298 .SH OPERANDS
290 299 .sp
291 300 .LP
292 301 The following operands are supported:
293 302 .sp
294 303 .ne 2
295 304 .na
296 305 \fB\fIfile\fR\fR
297 306 .ad
298 307 .RS 8n
299 308 A path name of a file to be searched for the patterns. If no \fIfile\fR
300 309 operands are specified, the standard input is used.
301 310 .RE
302 311
303 312 .SS "/usr/bin/grep"
304 313 .sp
305 314 .ne 2
306 315 .na
307 316 \fB\fIpattern\fR\fR
308 317 .ad
309 318 .RS 11n
310 319 Specifies a pattern to be used during the search for input.
311 320 .RE
312 321
313 322 .SS "/usr/xpg4/bin/grep"
314 323 .sp
315 324 .ne 2
316 325 .na
317 326 \fB\fIpattern\fR\fR
318 327 .ad
319 328 .RS 11n
320 329 Specifies one or more patterns to be used during the search for input. This
321 330 operand is treated as if it were specified as \fB-e\fR \fIpattern_list\fR.
322 331 .RE
323 332
324 333 .SH USAGE
325 334 .sp
326 335 .LP
327 336 The \fB-e\fR \fIpattern_list\fR option has the same effect as the
328 337 \fIpattern_list\fR operand, but is useful when \fIpattern_list\fR begins with
329 338 the hyphen delimiter. It is also useful when it is more convenient to provide
330 339 multiple patterns as separate arguments.
331 340 .sp
332 341 .LP
333 342 Multiple \fB-e\fR and \fB-f\fR options are accepted and \fBgrep\fR uses all of
334 343 the patterns it is given while matching input text lines. Notice that the order
335 344 of evaluation is not specified. If an implementation finds a null string as a
336 345 pattern, it is allowed to use that pattern first, matching every line, and
337 346 effectively ignore any other patterns.
338 347 .sp
339 348 .LP
340 349 The \fB-q\fR option provides a means of easily determining whether or not a
341 350 pattern (or string) exists in a group of files. When searching several files,
342 351 it provides a performance improvement (because it can quit as soon as it finds
343 352 the first match) and requires less care by the user in choosing the set of
344 353 files to supply as arguments (because it exits zero if it finds a match even if
345 354 \fBgrep\fR detected an access or read error on earlier file operands).
346 355 .SS "Large File Behavior"
347 356 .sp
348 357 .LP
349 358 See \fBlargefile\fR(5) for the description of the behavior of \fBgrep\fR when
350 359 encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
351 360 .SH EXAMPLES
352 361 .LP
353 362 \fBExample 1 \fRFinding All Uses of a Word
354 363 .sp
355 364 .LP
356 365 To find all uses of the word "\fBPosix\fR" (in any case) in the file
357 366 \fBtext.mm\fR, and write with line numbers:
358 367
359 368 .sp
360 369 .in +2
361 370 .nf
362 371 example% \fB/usr/bin/grep -i -n posix text.mm\fR
363 372 .fi
364 373 .in -2
365 374 .sp
366 375
367 376 .LP
368 377 \fBExample 2 \fRFinding All Empty Lines
369 378 .sp
370 379 .LP
371 380 To find all empty lines in the standard input:
372 381
373 382 .sp
374 383 .in +2
375 384 .nf
376 385 example% \fB/usr/bin/grep ^$\fR
377 386 .fi
378 387 .in -2
379 388 .sp
380 389
381 390 .sp
382 391 .LP
383 392 or
384 393
385 394 .sp
386 395 .in +2
387 396 .nf
388 397 example% \fB/usr/bin/grep -v .\fR
389 398 .fi
390 399 .in -2
391 400 .sp
392 401
393 402 .LP
394 403 \fBExample 3 \fRFinding Lines Containing Strings
395 404 .sp
396 405 .LP
397 406 All of the following commands print all lines containing strings \fBabc\fR or
398 407 \fBdef\fR or both:
399 408
400 409 .sp
401 410 .in +2
402 411 .nf
403 412 example% \fB/usr/xpg4/bin/grep 'abc
404 413 def'\fR
405 414 example% \fB/usr/xpg4/bin/grep -e 'abc
406 415 def'\fR
407 416 example% \fB/usr/xpg4/bin/grep -e 'abc' -e 'def'\fR
408 417 example% \fB/usr/xpg4/bin/grep -E 'abc|def'\fR
409 418 example% \fB/usr/xpg4/bin/grep -E -e 'abc|def'\fR
410 419 example% \fB/usr/xpg4/bin/grep -E -e 'abc' -e 'def'\fR
411 420 example% \fB/usr/xpg4/bin/grep -E 'abc
412 421 def'\fR
413 422 example% \fB/usr/xpg4/bin/grep -E -e 'abc
414 423 def'\fR
415 424 example% \fB/usr/xpg4/bin/grep -F -e 'abc' -e 'def'\fR
416 425 example% \fB/usr/xpg4/bin/grep -F 'abc
417 426 def'\fR
418 427 example% \fB/usr/xpg4/bin/grep -F -e 'abc
419 428 def'\fR
420 429 .fi
421 430 .in -2
422 431 .sp
423 432
424 433 .LP
425 434 \fBExample 4 \fRFinding Lines with Matching Strings
426 435 .sp
427 436 .LP
428 437 Both of the following commands print all lines matching exactly \fBabc\fR or
429 438 \fBdef\fR:
430 439
431 440 .sp
432 441 .in +2
433 442 .nf
434 443 example% \fB/usr/xpg4/bin/grep -E '^abc$ ^def$'\fR
435 444 example% \fB/usr/xpg4/bin/grep -F -x 'abc def'\fR
436 445 .fi
437 446 .in -2
438 447 .sp
439 448
440 449 .SH ENVIRONMENT VARIABLES
441 450 .sp
442 451 .LP
443 452 See \fBenviron\fR(5) for descriptions of the following environment variables
444 453 that affect the execution of \fBgrep\fR: \fBLANG\fR, \fBLC_ALL\fR,
445 454 \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
446 455 .SH EXIT STATUS
447 456 .sp
448 457 .LP
449 458 The following exit values are returned:
450 459 .sp
451 460 .ne 2
452 461 .na
453 462 \fB\fB0\fR\fR
454 463 .ad
455 464 .RS 5n
456 465 One or more matches were found.
457 466 .RE
458 467
459 468 .sp
460 469 .ne 2
461 470 .na
462 471 \fB\fB1\fR\fR
463 472 .ad
464 473 .RS 5n
465 474 No matches were found.
466 475 .RE
467 476
468 477 .sp
469 478 .ne 2
470 479 .na
471 480 \fB\fB2\fR\fR
472 481 .ad
473 482 .RS 5n
474 483 Syntax errors or inaccessible files (even if matches were found).
475 484 .RE
476 485
477 486 .SH ATTRIBUTES
478 487 .sp
479 488 .LP
480 489 See \fBattributes\fR(5) for descriptions of the following attributes:
481 490 .SS "/usr/bin/grep"
482 491 .sp
483 492
484 493 .sp
485 494 .TS
486 495 box;
487 496 c | c
488 497 l | l .
489 498 ATTRIBUTE TYPE ATTRIBUTE VALUE
490 499 _
491 500 CSI Not Enabled
492 501 .TE
493 502
494 503 .SS "/usr/xpg4/bin/grep"
495 504 .sp
496 505
497 506 .sp
498 507 .TS
499 508 box;
500 509 c | c
501 510 l | l .
502 511 ATTRIBUTE TYPE ATTRIBUTE VALUE
503 512 _
504 513 CSI Enabled
505 514 _
506 515 Interface Stability Committed
507 516 _
508 517 Standard See \fBstandards\fR(5).
509 518 .TE
510 519
511 520 .SH SEE ALSO
512 521 .sp
513 522 .LP
514 523 \fBegrep\fR(1), \fBfgrep\fR(1), \fBsed\fR(1), \fBsh\fR(1), \fBattributes\fR(5),
515 524 \fBenviron\fR(5), \fBlargefile\fR(5), \fBregex\fR(5), \fBregexp\fR(5),
516 525 \fBstandards\fR(5)
517 526 .SH NOTES
518 527 .SS "/usr/bin/grep"
519 528 .sp
520 529 .LP
521 530 Lines are limited only by the size of the available virtual memory. If there is
522 531 a line with embedded nulls, \fBgrep\fR only matches up to the first null. If
523 532 the line matches, the entire line is printed.
524 533 .SS "/usr/xpg4/bin/grep"
525 534 .sp
526 535 .LP
527 536 The results are unspecified if input files contain lines longer than
528 537 \fBLINE_MAX\fR bytes or contain binary data. \fBLINE_MAX\fR is defined in
529 538 \fB/usr/include/limits.h\fR.
↓ open down ↓ |
422 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX