From owner-svn-src-all@freebsd.org Thu Nov 19 18:58:16 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6C2F7471E43; Thu, 19 Nov 2020 18:58:16 +0000 (UTC) (envelope-from fernape@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CcTTh2cDLz3H0x; Thu, 19 Nov 2020 18:58:16 +0000 (UTC) (envelope-from fernape@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 47FAADCC; Thu, 19 Nov 2020 18:58:16 +0000 (UTC) (envelope-from fernape@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0AJIwGdA070801; Thu, 19 Nov 2020 18:58:16 GMT (envelope-from fernape@FreeBSD.org) Received: (from fernape@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0AJIwGPC070800; Thu, 19 Nov 2020 18:58:16 GMT (envelope-from fernape@FreeBSD.org) Message-Id: <202011191858.0AJIwGPC070800@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: fernape set sender to fernape@FreeBSD.org using -f From: =?UTF-8?Q?Fernando_Apestegu=c3=ada?= Date: Thu, 19 Nov 2020 18:58:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367850 - head/usr.bin/grep X-SVN-Group: head X-SVN-Commit-Author: fernape X-SVN-Commit-Paths: head/usr.bin/grep X-SVN-Commit-Revision: 367850 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Nov 2020 18:58:16 -0000 Author: fernape (ports committer) Date: Thu Nov 19 18:58:15 2020 New Revision: 367850 URL: https://svnweb.freebsd.org/changeset/base/367850 Log: grep(1): Add more EXAMPLES * Add more EXAMPLES covering flags: -A, -B, -c, -f, -i, -H, -l, -q, -R, -w * While here, change existing wording to use the imperative (remove "To find") * Reword first example to be consistent with how grep(1) understand words (-w) Approved by: manpages (bcr@) Differential Revision: https://reviews.freebsd.org/D27264 Modified: head/usr.bin/grep/grep.1 Modified: head/usr.bin/grep/grep.1 ============================================================================== --- head/usr.bin/grep/grep.1 Thu Nov 19 18:37:28 2020 (r367849) +++ head/usr.bin/grep/grep.1 Thu Nov 19 18:58:15 2020 (r367850) @@ -30,7 +30,7 @@ .\" .\" @(#)grep.1 8.3 (Berkeley) 4/18/94 .\" -.Dd August 7, 2020 +.Dd November 19, 2020 .Dt GREP 1 .Os .Sh NAME @@ -456,13 +456,27 @@ An error occurred. .Sh EXAMPLES .Bl -dash .It -To find all occurrences of the word +Find all occurrences of the pattern .Sq patricia in a file: .Pp .Dl $ grep 'patricia' myfile .It -To find all occurrences of the pattern +Same as above but looking only for complete words: +.Pp +.Dl $ grep -w 'patricia' myfile +.It +Count occurrences of the exact pattern +.Sq FOO +: +.Pp +.Dl $ grep -c FOO myfile +.It +Same as above but ignoring case: +.Pp +.Dl $ grep -c -i FOO myfile +.It +Find all occurrences of the pattern .Ql .Pp at the beginning of a line: .Pp @@ -480,20 +494,55 @@ escapes the .Ql \&. , which would otherwise match any character. .It -To find all lines in a file which do not contain the words +Find all lines in a file which do not contain the words .Sq foo or .Sq bar : .Pp .Dl $ grep -v -e 'foo' -e 'bar' myfile .It -A simple example of an extended regular expression: +Peruse the file +.Sq calendar +looking for either 19, 20, or 25 using extended regular expressions: .Pp .Dl $ egrep '19|20|25' calendar +.It +Show matching lines and the name of the +.Sq *.h +files which contain the pattern +.Sq FIXME . +Do the search recursively from the +.Pa /usr/src/sys/arm +directory .Pp -Peruses the file -.Sq calendar -looking for either 19, 20, or 25. +.Dl $ grep -H -R FIXME --include=*.h /usr/src/sys/arm/ +.It +Same as above but show only the name of the matching file: +.Pp +.Dl $ grep -l -R FIXME --include=*.h /usr/src/sys/arm/ +.It +Show lines containing the text +.Sq foo . +The matching part of the output is colored and every line is prefixed with +the line number and the offset in the file for those lines that matched. +.Pp +.Dl $ grep -b --colour -n foo myfile +.It +Show lines that match the extended regular expression patterns read from the +standard input: +.Pp +.Dl $ echo -e 'Free\enBSD\enAll.*reserved' | grep -E -f - myfile +.It +Show lines from the output of the +.Xr pciconf 8 +command matching the specified extended regular expression along with +three lines of leading context and one line of trailing context: +.Pp +.Dl $ pciconf -lv | grep -B3 -A1 -E 'class.*=.*storage' +.It +Suppress any output and use the exit status to show an appropriate message: +.Pp +.Dl $ grep -q foo myfile && echo File matches .El .Sh SEE ALSO .Xr ed 1 ,