xref: /illumos-gate/usr/src/man/man1/grep.1 (revision bbf215553c7233fbab8a0afdf1fac74c44781867)
1e54e6a39SYuri Pankov.\"
2e54e6a39SYuri Pankov.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3e54e6a39SYuri Pankov.\" permission to reproduce portions of its copyrighted documentation.
4e54e6a39SYuri Pankov.\" Original documentation from The Open Group can be obtained online at
5c10c16deSRichard Lowe.\" http://www.opengroup.org/bookstore/.
6e54e6a39SYuri Pankov.\"
7e54e6a39SYuri Pankov.\" The Institute of Electrical and Electronics Engineers and The Open
8e54e6a39SYuri Pankov.\" Group, have given us permission to reprint portions of their
9e54e6a39SYuri Pankov.\" documentation.
10e54e6a39SYuri Pankov.\"
11e54e6a39SYuri Pankov.\" In the following statement, the phrase ``this text'' refers to portions
12e54e6a39SYuri Pankov.\" of the system documentation.
13e54e6a39SYuri Pankov.\"
14e54e6a39SYuri Pankov.\" Portions of this text are reprinted and reproduced in electronic form
15e54e6a39SYuri Pankov.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16e54e6a39SYuri Pankov.\" Standard for Information Technology -- Portable Operating System
17e54e6a39SYuri Pankov.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18e54e6a39SYuri Pankov.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19e54e6a39SYuri Pankov.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20e54e6a39SYuri Pankov.\" between these versions and the original IEEE and The Open Group
21e54e6a39SYuri Pankov.\" Standard, the original IEEE and The Open Group Standard is the referee
22e54e6a39SYuri Pankov.\" document.  The original Standard can be obtained online at
23e54e6a39SYuri Pankov.\" http://www.opengroup.org/unix/online.html.
24e54e6a39SYuri Pankov.\"
25c10c16deSRichard Lowe.\" This notice shall appear on any product containing this material.
26e54e6a39SYuri Pankov.\"
27e54e6a39SYuri Pankov.\" The contents of this file are subject to the terms of the
28e54e6a39SYuri Pankov.\" Common Development and Distribution License (the "License").
29e54e6a39SYuri Pankov.\" You may not use this file except in compliance with the License.
30e54e6a39SYuri Pankov.\"
31e54e6a39SYuri Pankov.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32e54e6a39SYuri Pankov.\" or http://www.opensolaris.org/os/licensing.
33e54e6a39SYuri Pankov.\" See the License for the specific language governing permissions
34e54e6a39SYuri Pankov.\" and limitations under the License.
35e54e6a39SYuri Pankov.\"
36e54e6a39SYuri Pankov.\" When distributing Covered Code, include this CDDL HEADER in each
37e54e6a39SYuri Pankov.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38e54e6a39SYuri Pankov.\" If applicable, add the following below this CDDL HEADER, with the
39e54e6a39SYuri Pankov.\" fields enclosed by brackets "[]" replaced with your own identifying
40e54e6a39SYuri Pankov.\" information: Portions Copyright [yyyy] [name of copyright owner]
41e54e6a39SYuri Pankov.\"
42e54e6a39SYuri Pankov.\"
43e54e6a39SYuri Pankov.\" Copyright 1989 AT&T
44e54e6a39SYuri Pankov.\" Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
45e54e6a39SYuri Pankov.\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved
46e54e6a39SYuri Pankov.\" Copyright 2018 Nexenta Systems, Inc.
472e5ac464SRobert Mustacchi.\" Copyright 2020 Oxide Computer Company
48e54e6a39SYuri Pankov.\"
4981dd18d8SRobert Mustacchi.Dd August 13, 2020
50e54e6a39SYuri Pankov.Dt GREP 1
51e54e6a39SYuri Pankov.Os
52e54e6a39SYuri Pankov.Sh NAME
53e54e6a39SYuri Pankov.Nm grep ,
54e54e6a39SYuri Pankov.Nm egrep ,
55e54e6a39SYuri Pankov.Nm fgrep
56e54e6a39SYuri Pankov.Nd search a file for a pattern
57e54e6a39SYuri Pankov.Sh SYNOPSIS
58e54e6a39SYuri Pankov.Nm grep
59e54e6a39SYuri Pankov.Op Fl E Ns | Ns Fl F
6081dd18d8SRobert Mustacchi.Op Fl bchHilLnorRsqvwx
61e54e6a39SYuri Pankov.Op Fl A Ar num
62e54e6a39SYuri Pankov.Op Fl B Ar num
63e54e6a39SYuri Pankov.Op Fl C Ar num Ns | Ns Fl Ns Ar num
648ccd0217SRobert Mustacchi.Op Fl -label Ns = Ns Ar name
65e54e6a39SYuri Pankov.Oo Fl e Ar pattern_list Oc Ns ...
66e54e6a39SYuri Pankov.Oo Fl f Ar pattern_file Oc Ns ...
67e54e6a39SYuri Pankov.Op Ar pattern_list
68e54e6a39SYuri Pankov.Oo Ar file Oc Ns ...
69e54e6a39SYuri Pankov.Sh DESCRIPTION
70e54e6a39SYuri PankovThe
71e54e6a39SYuri Pankov.Nm
72e54e6a39SYuri Pankovutility searches text files for a pattern and prints all lines that contain that
73e54e6a39SYuri Pankovpattern.
74e54e6a39SYuri PankovIf no files are specified,
75e54e6a39SYuri Pankov.Nm
76e54e6a39SYuri Pankovassumes standard input.
77e54e6a39SYuri PankovNormally, each line found is copied to standard output.
78e54e6a39SYuri PankovThe file name is printed before each line found if there is more than one input
79e54e6a39SYuri Pankovfile.
80e54e6a39SYuri Pankov.Pp
81e54e6a39SYuri Pankov.Nm
82e54e6a39SYuri Pankovhandles patterns as basic regular expressions (BREs);
83e54e6a39SYuri Pankov.Nm egrep
84e54e6a39SYuri Pankov.Pq same as Nm Fl E
85e54e6a39SYuri Pankovhandles patterns as extended regular expressions (EREs);
86e54e6a39SYuri Pankov.Nm fgrep
87e54e6a39SYuri Pankov.Pq same as Nm Fl F
88e54e6a39SYuri Pankovhandles patterns as fixed strings.
89e54e6a39SYuri Pankov.Sh OPTIONS
90d2d52addSAlexander PyhalovThe following options are supported:
91e54e6a39SYuri Pankov.Bl -tag -width Ds
92e54e6a39SYuri Pankov.It Fl A Ar num
93e54e6a39SYuri PankovPrints
94e54e6a39SYuri Pankov.Ar num
95e54e6a39SYuri Pankovinput lines of context after each matching line.
96e54e6a39SYuri PankovIf there are multiple matching lines, their context lines are separated by a
97e54e6a39SYuri Pankov.Ql --
98d2d52addSAlexander Pyhalovdelimiter line.
99e54e6a39SYuri Pankov.It Fl b
100e54e6a39SYuri PankovPrecedes each line by the block number on which it was found.
101e54e6a39SYuri PankovThis can be useful in locating block numbers by context (first block is 0).
102e54e6a39SYuri Pankov.It Fl B Ar num
103e54e6a39SYuri PankovPrints
104e54e6a39SYuri Pankov.Ar num
105e54e6a39SYuri Pankovinput lines of context before each matching line.
106e54e6a39SYuri PankovIf there are multiple matching lines, their context lines are separated by a
107e54e6a39SYuri Pankov.Ql --
108d2d52addSAlexander Pyhalovdelimiter line.
109e54e6a39SYuri Pankov.It Fl c
110c10c16deSRichard LowePrints only a count of the lines that contain the pattern.
111e54e6a39SYuri PankovOverrides
1122e5ac464SRobert Mustacchi.Fl l
1132e5ac464SRobert Mustacchiand
1142e5ac464SRobert Mustacchi.Fl L .
115e54e6a39SYuri Pankov.It Fl C Ar num Ns \&, Fl Ns Ar num
116e54e6a39SYuri PankovPrints
117e54e6a39SYuri Pankov.Ar num
118e54e6a39SYuri Pankovinput lines of context before and
119e54e6a39SYuri Pankov.Ar number
120e54e6a39SYuri Pankovinput lines of context after each matching line.
121e54e6a39SYuri PankovIf there are multiple matching lines, their context lines are separated by a
122e54e6a39SYuri Pankov.Ql --
123e54e6a39SYuri Pankovdelimiter line.
124e54e6a39SYuri Pankov.It Fl e Ar pattern_list
125e54e6a39SYuri PankovSpecifies one or more patterns to be used during the search for input.
126e54e6a39SYuri PankovPatterns in
127e54e6a39SYuri Pankov.Ar pattern_list
128e54e6a39SYuri Pankovmust be separated by a NEWLINE character.
129e54e6a39SYuri PankovA null pattern can be specified by two adjacent newline characters in
130e54e6a39SYuri Pankov.Ar pattern_list .
131e54e6a39SYuri PankovUnless the
132e54e6a39SYuri Pankov.Fl E
133e54e6a39SYuri Pankovor
134e54e6a39SYuri Pankov.Fl F
135e54e6a39SYuri Pankovoption is also specified, each pattern is treated as a BRE, as described in
136*bbf21555SRichard Lowe.Xr regex 7 .
137e54e6a39SYuri Pankov.It Fl E
138e54e6a39SYuri PankovMatches using extended regular expressions.
139e54e6a39SYuri PankovTreats each pattern specified as an ERE, as described in
140*bbf21555SRichard Lowe.Xr regex 7 .
141e54e6a39SYuri PankovIf any entire ERE pattern matches an input line, the line is matched.
142e54e6a39SYuri PankovA null ERE matches every line.
143e54e6a39SYuri Pankov.It Fl f Ar pattern_file
144d2d52addSAlexander PyhalovReads one or more patterns from the file named by the path name
145e54e6a39SYuri Pankov.Ar pattern_file .
146e54e6a39SYuri PankovPatterns in
147e54e6a39SYuri Pankov.Ar pattern_file
148e54e6a39SYuri Pankovare terminated by a NEWLINE character.
149e54e6a39SYuri PankovA null pattern can be specified by an empty line in
150e54e6a39SYuri Pankov.Ar pattern_file .
151e54e6a39SYuri PankovUnless the
152e54e6a39SYuri Pankov.Fl E
153e54e6a39SYuri Pankovor
154e54e6a39SYuri Pankov.Fl F
155e54e6a39SYuri Pankovoption is also specified, each pattern is treated as a BRE, as described in
156*bbf21555SRichard Lowe.Xr regex 7 .
157e54e6a39SYuri Pankov.It Fl F
158e54e6a39SYuri PankovMatches using fixed strings.
159e54e6a39SYuri PankovTreats each pattern specified as a string instead of a regular expression.
160e54e6a39SYuri PankovIf an input line contains any of the patterns as a contiguous sequence of bytes,
161e54e6a39SYuri Pankovthe line is matched.
162e54e6a39SYuri PankovA null string matches every line.
163e54e6a39SYuri Pankov.It Fl h
164c10c16deSRichard LowePrevents the name of the file containing the matching line from being prepended
165e54e6a39SYuri Pankovto that line.
166e54e6a39SYuri PankovUsed when searching multiple files.
167e54e6a39SYuri Pankov.It Fl H
168e54e6a39SYuri PankovPrecedes each line by the name of the file containing the matching line.
169e54e6a39SYuri Pankov.It Fl i
170c10c16deSRichard LoweIgnores upper/lower case distinction during comparisons.
1718ccd0217SRobert Mustacchi.It Fl -label Ns = Ns Ar name
1728ccd0217SRobert MustacchiWhen the name of the matching file is printed
1738ccd0217SRobert Mustacchi.Pq Fl H ,
1748ccd0217SRobert Mustacchiinstead of printing the string
1758ccd0217SRobert Mustacchi.Ql (standard input)
1768ccd0217SRobert Mustacchithe string
1778ccd0217SRobert Mustacchi.Ar name
1788ccd0217SRobert Mustacchiis printed instead.
1798ccd0217SRobert MustacchiSee
1808ccd0217SRobert Mustacchi.Sx Example 5 .
181e54e6a39SYuri Pankov.It Fl l
182c10c16deSRichard LowePrints only the names of files with matching lines, separated by NEWLINE
183e54e6a39SYuri Pankovcharacters.
184e54e6a39SYuri PankovDoes not repeat the names of files when the pattern is found more than once.
1852e5ac464SRobert MustacchiIf both
1862e5ac464SRobert Mustacchi.Fl l
1872e5ac464SRobert Mustacchiand
1882e5ac464SRobert Mustacchi.Fl L
1892e5ac464SRobert Mustacchiare specified, only the last specified takes effect.
1902e5ac464SRobert MustacchiOverrides
1912e5ac464SRobert Mustacchi.Fl H .
1922e5ac464SRobert Mustacchi.It Fl L
1932e5ac464SRobert MustacchiThe opposite of the
1942e5ac464SRobert Mustacchi.Fl l
1952e5ac464SRobert Mustacchiflag.
1962e5ac464SRobert MustacchiPrints only the names of files without matching lines.
1972e5ac464SRobert MustacchiIf both
1982e5ac464SRobert Mustacchi.Fl l
1992e5ac464SRobert Mustacchiand
2002e5ac464SRobert Mustacchi.Fl L
2012e5ac464SRobert Mustacchiare specified, only the last specified takes effect.
202e54e6a39SYuri PankovOverrides
203e54e6a39SYuri Pankov.Fl H .
204e54e6a39SYuri Pankov.It Fl n
205c10c16deSRichard LowePrecedes each line by its line number in the file (first line is 1).
20681dd18d8SRobert Mustacchi.It Fl o
20781dd18d8SRobert MustacchiPrints only the matching part of a line.
20881dd18d8SRobert MustacchiIf a pattern appears more than once in a line, it will be matched and
20981dd18d8SRobert Mustacchiprinted multiple times.
21081dd18d8SRobert Mustacchi.Pp
21181dd18d8SRobert MustacchiThe
21281dd18d8SRobert Mustacchi.Fl o
21381dd18d8SRobert Mustacchioption is overridden when any of the
21481dd18d8SRobert Mustacchi.Fl l ,
21581dd18d8SRobert Mustacchi.Fl L ,
21681dd18d8SRobert Mustacchior
21781dd18d8SRobert Mustacchi.Fl c
21881dd18d8SRobert Mustacchioptions are specified.
21981dd18d8SRobert MustacchiWhen the
22081dd18d8SRobert Mustacchi.Fl o
22181dd18d8SRobert Mustacchioption is specified, all context options are ignored.
22281dd18d8SRobert MustacchiThe
22381dd18d8SRobert Mustacchi.Fl o
22481dd18d8SRobert Mustacchiand
22581dd18d8SRobert Mustacchi.Fl v
22681dd18d8SRobert Mustacchioptions are not supported together at this time.
227e54e6a39SYuri Pankov.It Fl q
228e54e6a39SYuri PankovQuiet.
229e54e6a39SYuri PankovDoes not write anything to the standard output, regardless of matching lines.
230e54e6a39SYuri PankovExits with zero status if an input line is selected.
231e54e6a39SYuri PankovOverrides
2322e5ac464SRobert Mustacchi.Fl c ,
2332e5ac464SRobert Mustacchi.Fl l ,
234e54e6a39SYuri Pankovand
2352e5ac464SRobert Mustacchi.Fl L .
236e54e6a39SYuri Pankov.It Fl r
237e54e6a39SYuri PankovRead all files under each directory, recursively.
238e54e6a39SYuri PankovFollow symbolic links on the command line, but skip symlinks that are
239e54e6a39SYuri Pankovencountered recursively.
240e54e6a39SYuri PankovIf file is a device, FIFO, or socket, skip it.
241e54e6a39SYuri Pankov.It Fl R
242e52fb54bSAlexander EreminRead all files under each directory, recursively, following all symbolic links.
243e54e6a39SYuri Pankov.It Fl s
244c10c16deSRichard LoweSuppresses error messages about nonexistent or unreadable files.
245e54e6a39SYuri Pankov.It Fl v
246c10c16deSRichard LowePrints all lines except those that contain the pattern.
247e54e6a39SYuri Pankov.It Fl w
248e54e6a39SYuri PankovSearches for the expression as a word as if surrounded by
249e54e6a39SYuri Pankov.Ql \e<
250e54e6a39SYuri Pankovand
251e54e6a39SYuri Pankov.Ql \e> .
252e54e6a39SYuri Pankov.It Fl x
253c10c16deSRichard LoweConsiders only input lines that use all characters in the line to match an
254c10c16deSRichard Loweentire fixed string or regular expression to be matching lines.
255e54e6a39SYuri Pankov.El
256e54e6a39SYuri Pankov.Sh OPERANDS
257c10c16deSRichard LoweThe following operands are supported:
258e54e6a39SYuri Pankov.Bl -tag -width Ds
259e54e6a39SYuri Pankov.It Ar file
260e54e6a39SYuri PankovA path name of a file to be searched for the patterns.
261e54e6a39SYuri PankovIf no
262e54e6a39SYuri Pankov.Ar file
263c10c16deSRichard Loweoperands are specified, the standard input is used.
264e54e6a39SYuri Pankov.It Ar pattern_list
265e54e6a39SYuri PankovSpecifies one or more patterns to be used during the search for input.
266e54e6a39SYuri PankovThis operand is treated as if it were specified as
267e54e6a39SYuri Pankov.Fl e Ar pattern_list .
268e54e6a39SYuri PankovShould not be specified if either
269e54e6a39SYuri Pankov.Fl e
270c10c16deSRichard Loweor
271e54e6a39SYuri Pankov.Fl f
272e54e6a39SYuri Pankovis specified.
273e54e6a39SYuri Pankov.El
274e54e6a39SYuri Pankov.Sh USAGE
275e54e6a39SYuri PankovBe careful using the characters
276e54e6a39SYuri Pankov.Ql $ ,
277e54e6a39SYuri Pankov.Ql * ,
278e54e6a39SYuri Pankov.Ql \&[ ,
279e54e6a39SYuri Pankov.Ql ^ ,
280e54e6a39SYuri Pankov.Ql | ,
281e54e6a39SYuri Pankov.Ql \&( ,
282e54e6a39SYuri Pankov.Ql \&) ,
283e54e6a39SYuri Pankovand
284e54e6a39SYuri Pankov.Ql \e
285e54e6a39SYuri Pankovin the
286e54e6a39SYuri Pankov.Ar pattern_list
287e54e6a39SYuri Pankovbecause they are also meaningful to the shell.
288e54e6a39SYuri PankovIt is safest to enclose the entire
289e54e6a39SYuri Pankov.Ar pattern_list
290e54e6a39SYuri Pankovin single quotes:
291e54e6a39SYuri Pankov.Li '...' .
292e54e6a39SYuri Pankov.Pp
293e54e6a39SYuri PankovThe
294e54e6a39SYuri Pankov.Fl e Ar pattern
295e54e6a39SYuri Pankovoption has the same effect as the
296e54e6a39SYuri Pankov.Ar pattern
297e54e6a39SYuri Pankovoperand, but is useful when
298e54e6a39SYuri Pankov.Ar pattern
299e54e6a39SYuri Pankovbegins with the hyphen delimiter.
300e54e6a39SYuri PankovIt is also useful when it is more convenient to provide multiple patterns as
301e54e6a39SYuri Pankovseparate arguments.
302e54e6a39SYuri Pankov.Pp
303e54e6a39SYuri PankovMultiple
304e54e6a39SYuri Pankov.Fl e
305e54e6a39SYuri Pankovand
306e54e6a39SYuri Pankov.Fl f
307e54e6a39SYuri Pankovoptions are accepted and
308e54e6a39SYuri Pankov.Nm
309e54e6a39SYuri Pankovuses all of the patterns it is given while matching input text lines.
310e54e6a39SYuri PankovNotice that the order of evaluation is not specified.
311e54e6a39SYuri PankovIf an implementation finds a null string as a pattern, it is allowed to use that
312e54e6a39SYuri Pankovpattern first, matching every line, and effectively ignore any other patterns.
313e54e6a39SYuri Pankov.Pp
314e54e6a39SYuri PankovThe
315e54e6a39SYuri Pankov.Fl q
316e54e6a39SYuri Pankovoption provides a means of easily determining whether or not a pattern (or
317e54e6a39SYuri Pankovstring) exists in a group of files.
318e54e6a39SYuri PankovWhen searching several files, it provides a performance improvement (because it
319e54e6a39SYuri Pankovcan quit as soon as it finds the first match) and requires less care by the user
320e54e6a39SYuri Pankovin choosing the set of files to supply as arguments (because it exits zero if it
321e54e6a39SYuri Pankovfinds a match even if
322e54e6a39SYuri Pankov.Nm
323e54e6a39SYuri Pankovdetected an access or read error on earlier file operands).
324e54e6a39SYuri Pankov.Ss Large File Behavior
325e54e6a39SYuri PankovSee
326*bbf21555SRichard Lowe.Xr largefile 7
327e54e6a39SYuri Pankovfor the description of the behavior of
328e54e6a39SYuri Pankov.Nm
329e54e6a39SYuri Pankovwhen encountering files greater than or equal to 2 Gbyte (2^31 bytes).
330e54e6a39SYuri Pankov.Sh EXIT STATUS
331c10c16deSRichard LoweThe following exit values are returned:
332e54e6a39SYuri Pankov.Bl -tag -width Ds
333e54e6a39SYuri Pankov.It Sy 0
334c10c16deSRichard LoweOne or more matches were found.
335e54e6a39SYuri Pankov.It Sy 1
336c10c16deSRichard LoweNo matches were found.
337e54e6a39SYuri Pankov.It Sy 2
338c10c16deSRichard LoweSyntax errors or inaccessible files (even if matches were found).
339e54e6a39SYuri Pankov.El
340e54e6a39SYuri Pankov.Sh EXAMPLES
341e54e6a39SYuri Pankov.Bl -tag -width Ds
342e54e6a39SYuri Pankov.It Sy Example 1 No Finding All Uses of a Word
343e54e6a39SYuri PankovTo find all uses of the word
344e54e6a39SYuri Pankov.Ql Posix
345e54e6a39SYuri Pankov(in any case) in the file
346e54e6a39SYuri Pankov.Pa text.mm ,
347e54e6a39SYuri Pankovand write with line numbers:
348e54e6a39SYuri Pankov.Bd -literal
349e54e6a39SYuri Pankov$ grep -i -n posix text.mm
350e54e6a39SYuri Pankov.Ed
351e54e6a39SYuri Pankov.It Sy Example 2 No Finding All Empty Lines
352e54e6a39SYuri PankovTo find all empty lines in the standard input:
353e54e6a39SYuri Pankov.Bd -literal
354e54e6a39SYuri Pankov$ grep ^$
355e54e6a39SYuri Pankov.Ed
356e54e6a39SYuri Pankov.Pp
357e54e6a39SYuri Pankovor
358e54e6a39SYuri Pankov.Bd -literal
359e54e6a39SYuri Pankov$ grep -v .
360e54e6a39SYuri Pankov.Ed
361e54e6a39SYuri Pankov.It Sy Example 3 No Finding Lines Containing Strings
362e54e6a39SYuri PankovAll of the following commands print all lines containing strings
363e54e6a39SYuri Pankov.Ql abc
364e54e6a39SYuri Pankovor
365e54e6a39SYuri Pankov.Ql def
366e54e6a39SYuri Pankovor both:
367e54e6a39SYuri Pankov.Bd -literal
368e54e6a39SYuri Pankov$ grep 'abc
369e54e6a39SYuri Pankovdef'
370e54e6a39SYuri Pankov$ grep -e 'abc
371e54e6a39SYuri Pankovdef'
372e54e6a39SYuri Pankov$ grep -e 'abc' -e 'def'
373e54e6a39SYuri Pankov$ grep -E 'abc|def'
374e54e6a39SYuri Pankov$ grep -E -e 'abc|def'
375e54e6a39SYuri Pankov$ grep -E -e 'abc' -e 'def'
376e54e6a39SYuri Pankov$ grep -E 'abc
377e54e6a39SYuri Pankovdef'
378e54e6a39SYuri Pankov$ grep -E -e 'abc
379e54e6a39SYuri Pankovdef'
380e54e6a39SYuri Pankov$ grep -F -e 'abc' -e 'def'
381e54e6a39SYuri Pankov$ grep -F 'abc
382e54e6a39SYuri Pankovdef'
383e54e6a39SYuri Pankov$ grep -F -e 'abc
384e54e6a39SYuri Pankovdef'
385e54e6a39SYuri Pankov.Ed
386e54e6a39SYuri Pankov.It Sy Example 4 No Finding Lines with Matching Strings
387e54e6a39SYuri PankovBoth of the following commands print all lines matching exactly
388e54e6a39SYuri Pankov.Ql abc
389e54e6a39SYuri Pankovor
390e54e6a39SYuri Pankov.Ql def :
391e54e6a39SYuri Pankov.Bd -literal
392e54e6a39SYuri Pankov$ grep -E '^abc$
393e54e6a39SYuri Pankov^def$'
394e54e6a39SYuri Pankov$ grep -F -x 'abc
395e54e6a39SYuri Pankovdef'
396e54e6a39SYuri Pankov.Ed
3978ccd0217SRobert Mustacchi.It Sy Example 5 No Using Fl -label
3988ccd0217SRobert MustacchiWhen piping standard input into
3998ccd0217SRobert Mustacchi.Nm ,
4008ccd0217SRobert Mustacchias part of a pipeline, occasionally it can be useful override the file
4018ccd0217SRobert Mustacchiname
4028ccd0217SRobert Mustacchi.Ql (standard input)
4038ccd0217SRobert Mustacchiwith something from the pipeline.
4048ccd0217SRobert MustacchiThis would output each matching line instead with the name of the input
4058ccd0217SRobert Mustacchifile.
4068ccd0217SRobert Mustacchi.Bd -literal
4078ccd0217SRobert Mustacchi$ for f in *.gz; do
4088ccd0217SRobert Mustacchi> gzcat $f | grep -H --label=$f foo
4098ccd0217SRobert Mustacchi> done
4108ccd0217SRobert Mustacchi.Ed
411e54e6a39SYuri Pankov.El
412e54e6a39SYuri Pankov.Sh ENVIRONMENT VARIABLES
413e54e6a39SYuri PankovSee
414*bbf21555SRichard Lowe.Xr environ 7
415e54e6a39SYuri Pankovfor descriptions of the following environment variables that affect the
416e54e6a39SYuri Pankovexecution of
417e54e6a39SYuri Pankov.Nm :
418e54e6a39SYuri Pankov.Ev LANG , LC_ALL , LC_COLLATE , LC_CTYPE , LC_MESSAGES ,
419e54e6a39SYuri Pankovand
420e54e6a39SYuri Pankov.Ev NLSPATH .
421e54e6a39SYuri Pankov.Sh CODE SET INDEPENDENCE
422e54e6a39SYuri Pankov.Sy Enabled
423e54e6a39SYuri Pankov.Sh INTERFACE STABILITY
424e54e6a39SYuri Pankov.Sy Committed
425e54e6a39SYuri Pankov.Sh SEE ALSO
426e54e6a39SYuri Pankov.Xr sed 1 ,
427e54e6a39SYuri Pankov.Xr sh 1 ,
428*bbf21555SRichard Lowe.Xr attributes 7 ,
429*bbf21555SRichard Lowe.Xr environ 7 ,
430*bbf21555SRichard Lowe.Xr largefile 7 ,
431*bbf21555SRichard Lowe.Xr regex 7 ,
432*bbf21555SRichard Lowe.Xr standards 7
433e54e6a39SYuri Pankov.Sh STANDARDS
434e54e6a39SYuri PankovThe
435e54e6a39SYuri Pankov.Nm
436e54e6a39SYuri Pankovutility is compliant with the
437e54e6a39SYuri Pankov.St -p1003.1-2008
438e54e6a39SYuri Pankovspecification with the exception of
439e54e6a39SYuri Pankov.Fl s
440e54e6a39SYuri Pankovoption being the same as
441e54e6a39SYuri Pankov.Fl q
442e54e6a39SYuri Pankovin current implementation for historic reasons.
443e54e6a39SYuri PankovThe flags
444e54e6a39SYuri Pankov.Op Fl AbBChHrRw
445e54e6a39SYuri Pankovare extensions to that specification.
446e54e6a39SYuri Pankov.Sh NOTES
447c10c16deSRichard LoweThe results are unspecified if input files contain lines longer than
448e54e6a39SYuri Pankov.Dv LINE_MAX
449e54e6a39SYuri Pankovbytes or contain binary data.
450e54e6a39SYuri Pankov.Dv LINE_MAX
451e54e6a39SYuri Pankovis defined in
452e54e6a39SYuri Pankov.In limits.h .
453e54e6a39SYuri Pankov.Pp
454e54e6a39SYuri PankovPortable applications should use
455e54e6a39SYuri Pankov.Nm Fl E
456e54e6a39SYuri Pankovand
457e54e6a39SYuri Pankov.Nm Fl F
458e54e6a39SYuri Pankovinstead of
459e54e6a39SYuri Pankov.Nm egrep
460e54e6a39SYuri Pankovand
461e54e6a39SYuri Pankov.Nm fgrep ,
462e54e6a39SYuri Pankovrespectively.
463e54e6a39SYuri Pankov.Sh HISTORY
464e54e6a39SYuri PankovThe
465e54e6a39SYuri Pankov.Nm grep
466e54e6a39SYuri Pankovcommand first appeared in
467e54e6a39SYuri Pankov.At v6 .
468e54e6a39SYuri Pankov.Pp
469e54e6a39SYuri PankovIn the past
470e54e6a39SYuri Pankov.Pa /usr/bin/grep ,
471e54e6a39SYuri Pankov.Pa /usr/bin/egrep ,
472e54e6a39SYuri Pankovand
473e54e6a39SYuri Pankov.Pa /usr/bin/fgrep
474e54e6a39SYuri Pankovwere separate implementations, and were not standard conforming, with standard
475e54e6a39SYuri Pankovconforming ones installed as
476e54e6a39SYuri Pankov.Pa /usr/xpg4/bin/grep ,
477e54e6a39SYuri Pankov.Pa /usr/xpg4/bin/egrep ,
478e54e6a39SYuri Pankovand
479e54e6a39SYuri Pankov.Pa /usr/xpg4/bin/fgrep ,
480e54e6a39SYuri Pankovrespectively.
481e54e6a39SYuri PankovNow all non-conforming implementations are removed, and the ones previously
482e54e6a39SYuri Pankovfound in
483e54e6a39SYuri Pankov.Pa /usr/xpg4/bin
484e54e6a39SYuri Pankovare installed in
485e54e6a39SYuri Pankov.Pa /usr/bin .
486