grep.1 (440cec3faf778469b36b998bb52aab7fbc43eae3) | grep.1 (5be3f744b4005f71f372929f883264eb59f729bb) |
---|---|
1.\" $NetBSD: grep.1,v 1.2 2011/02/16 01:31:33 joerg Exp $ 2.\" $FreeBSD$ 3.\" $OpenBSD: grep.1,v 1.38 2010/04/05 06:30:59 jmc Exp $ 4.\" Copyright (c) 1980, 1990, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions --- 16 unchanged lines hidden (view full) --- 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.\" @(#)grep.1 8.3 (Berkeley) 4/18/94 32.\" | 1.\" $NetBSD: grep.1,v 1.2 2011/02/16 01:31:33 joerg Exp $ 2.\" $FreeBSD$ 3.\" $OpenBSD: grep.1,v 1.38 2010/04/05 06:30:59 jmc Exp $ 4.\" Copyright (c) 1980, 1990, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions --- 16 unchanged lines hidden (view full) --- 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.\" @(#)grep.1 8.3 (Berkeley) 4/18/94 32.\" |
33.Dd August 7, 2020 | 33.Dd November 19, 2020 |
34.Dt GREP 1 35.Os 36.Sh NAME 37.Nm grep , 38.Nm egrep , 39.Nm fgrep , 40.Nm rgrep 41.Nd file pattern searcher --- 409 unchanged lines hidden (view full) --- 451.It Li 1 452No lines were selected. 453.It Li \*(Gt1 454An error occurred. 455.El 456.Sh EXAMPLES 457.Bl -dash 458.It | 34.Dt GREP 1 35.Os 36.Sh NAME 37.Nm grep , 38.Nm egrep , 39.Nm fgrep , 40.Nm rgrep 41.Nd file pattern searcher --- 409 unchanged lines hidden (view full) --- 451.It Li 1 452No lines were selected. 453.It Li \*(Gt1 454An error occurred. 455.El 456.Sh EXAMPLES 457.Bl -dash 458.It |
459To find all occurrences of the word | 459Find all occurrences of the pattern |
460.Sq patricia 461in a file: 462.Pp 463.Dl $ grep 'patricia' myfile 464.It | 460.Sq patricia 461in a file: 462.Pp 463.Dl $ grep 'patricia' myfile 464.It |
465To find all occurrences of the pattern | 465Same as above but looking only for complete words: 466.Pp 467.Dl $ grep -w 'patricia' myfile 468.It 469Count occurrences of the exact pattern 470.Sq FOO 471: 472.Pp 473.Dl $ grep -c FOO myfile 474.It 475Same as above but ignoring case: 476.Pp 477.Dl $ grep -c -i FOO myfile 478.It 479Find all occurrences of the pattern |
466.Ql .Pp 467at the beginning of a line: 468.Pp 469.Dl $ grep '^\e.Pp' myfile 470.Pp 471The apostrophes ensure the entire expression is evaluated by 472.Nm grep 473instead of by the user's shell. 474The caret 475.Ql ^ 476matches the null string at the beginning of a line, 477and the 478.Ql \e 479escapes the 480.Ql \&. , 481which would otherwise match any character. 482.It | 480.Ql .Pp 481at the beginning of a line: 482.Pp 483.Dl $ grep '^\e.Pp' myfile 484.Pp 485The apostrophes ensure the entire expression is evaluated by 486.Nm grep 487instead of by the user's shell. 488The caret 489.Ql ^ 490matches the null string at the beginning of a line, 491and the 492.Ql \e 493escapes the 494.Ql \&. , 495which would otherwise match any character. 496.It |
483To find all lines in a file which do not contain the words | 497Find all lines in a file which do not contain the words |
484.Sq foo 485or 486.Sq bar : 487.Pp 488.Dl $ grep -v -e 'foo' -e 'bar' myfile 489.It | 498.Sq foo 499or 500.Sq bar : 501.Pp 502.Dl $ grep -v -e 'foo' -e 'bar' myfile 503.It |
490A simple example of an extended regular expression: | 504Peruse the file 505.Sq calendar 506looking for either 19, 20, or 25 using extended regular expressions: |
491.Pp 492.Dl $ egrep '19|20|25' calendar | 507.Pp 508.Dl $ egrep '19|20|25' calendar |
509.It 510Show matching lines and the name of the 511.Sq *.h 512files which contain the pattern 513.Sq FIXME . 514Do the search recursively from the 515.Pa /usr/src/sys/arm 516directory |
|
493.Pp | 517.Pp |
494Peruses the file 495.Sq calendar 496looking for either 19, 20, or 25. | 518.Dl $ grep -H -R FIXME --include=*.h /usr/src/sys/arm/ 519.It 520Same as above but show only the name of the matching file: 521.Pp 522.Dl $ grep -l -R FIXME --include=*.h /usr/src/sys/arm/ 523.It 524Show lines containing the text 525.Sq foo . 526The matching part of the output is colored and every line is prefixed with 527the line number and the offset in the file for those lines that matched. 528.Pp 529.Dl $ grep -b --colour -n foo myfile 530.It 531Show lines that match the extended regular expression patterns read from the 532standard input: 533.Pp 534.Dl $ echo -e 'Free\enBSD\enAll.*reserved' | grep -E -f - myfile 535.It 536Show lines from the output of the 537.Xr pciconf 8 538command matching the specified extended regular expression along with 539three lines of leading context and one line of trailing context: 540.Pp 541.Dl $ pciconf -lv | grep -B3 -A1 -E 'class.*=.*storage' 542.It 543Suppress any output and use the exit status to show an appropriate message: 544.Pp 545.Dl $ grep -q foo myfile && echo File matches |
497.El 498.Sh SEE ALSO 499.Xr ed 1 , 500.Xr ex 1 , 501.Xr sed 1 , 502.Xr zgrep 1 , 503.Xr re_format 7 504.Sh STANDARDS --- 26 unchanged lines hidden --- | 546.El 547.Sh SEE ALSO 548.Xr ed 1 , 549.Xr ex 1 , 550.Xr sed 1 , 551.Xr zgrep 1 , 552.Xr re_format 7 553.Sh STANDARDS --- 26 unchanged lines hidden --- |