grep.1 (8091B)
1 '\" t 2 .\" Sccsid @(#)grep.1 1.36 (gritter) 8/14/05 3 .\" Parts taken from grep(1), Unix 7th edition: 4 .\" Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 5 .\" 6 .\" Redistribution and use in source and binary forms, with or without 7 .\" modification, are permitted provided that the following conditions 8 .\" are met: 9 .\" Redistributions of source code and documentation must retain the 10 .\" above copyright notice, this list of conditions and the following 11 .\" disclaimer. 12 .\" Redistributions in binary form must reproduce the above copyright 13 .\" notice, this list of conditions and the following disclaimer in the 14 .\" documentation and/or other materials provided with the distribution. 15 .\" All advertising materials mentioning features or use of this software 16 .\" must display the following acknowledgement: 17 .\" This product includes software developed or owned by Caldera 18 .\" International, Inc. 19 .\" Neither the name of Caldera International, Inc. nor the names of 20 .\" other contributors may be used to endorse or promote products 21 .\" derived from this software without specific prior written permission. 22 .\" 23 .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 24 .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 25 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 .\" ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 28 .\" LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 31 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 34 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 .TH GREP 1 "8/14/05" "Heirloom Toolchest" "User Commands" 36 .SH NAME 37 grep \- search a file for a pattern 38 .SH SYNOPSIS 39 .HP 40 .ad l 41 .nh 42 \fB/usr/5bin/grep\fR [\fB\-bchilnrRsvwz\fR] 43 \fIpattern\fR [\fIfile\fR\ ...] 44 .HP 45 .PD 0 46 .ad l 47 \fB/usr/5bin/posix/grep\fR [\fB\-E\fR|\fB\-F\fR] 48 \fB\-e\fI\ pattern_list\fR\ ... 49 [\fB\-f\fI\ pattern_file\fR] [\fB\-c\fR|\fB\-l\fR|\fB\-q\fR] 50 [\fB\-bhinrRsvwxz\fR] [\fIfile\fR\ ...] 51 .HP 52 .ad l 53 \fB/usr/5bin/posix/grep\fR [\fB\-E\fR|\fB\-F\fR] 54 \fB\-f\fI\ pattern_file\fR 55 [\fB\-e\fI\ pattern_list\fR\ ...] [\fB\-c\fR|\fB\-l\fR|\fB\-q\fR] 56 [\fB\-bhinrRsvwxz\fR] [\fIfile\fR\ ...] 57 .HP 58 .ad l 59 \fB/usr/5bin/posix/grep\fR [\fB\-E\fR|\fB\-F\fR] 60 [\fB\-c\fR|\fB\-l\fR|\fB\-q\fR] [\fB\-bhinrRsvwxz\fR] 61 \fIpattern_list\fR [\fIfile\fR\ ...] 62 .br 63 .PD 64 .ad b 65 .hy 1 66 .SH DESCRIPTION 67 The 68 .B grep 69 command searches the lines of the specified files 70 (or of standard input) 71 for occurrences of the regular expression 72 .I pattern. 73 The default behavior is to print each matching line to standard output. 74 .PP 75 The 76 .B /usr/5bin/grep 77 command accepts one pattern 78 that is treated as a simple regular expression; 79 it uses a compact nondeterministic algorithm. 80 .PP 81 The 82 .B /usr/5bin/posix/grep 83 command uses basic regular expressions by default 84 and accepts a newline-separated list of patterns 85 as described for the 86 .B \-e 87 option below. 88 It uses a deterministic algorithm with moderate space requirements 89 for most expressions; 90 backreferences, word delimiters, and multi-character collating elements 91 cause a nondeterministic algorithm to be used. 92 .PP 93 .B /usr/5bin/s42/grep 94 and 95 .B /usr/5bin/posix2001/grep 96 are identical to 97 .BR /usr/5bin/posix/grep . 98 .PP 99 See the description of 100 .IR ed (1) 101 for the specifications of simple and basic regular expressions. 102 .PP 103 Care should be taken when using the characters 104 $ * [ ^ | ? \' " ( ) and \e in the expression 105 as they are also meaningful to the Shell. 106 It is safest to enclose the entire expression 107 argument in single quotes \' \'. 108 .PP 109 Both 110 .B /usr/5bin/grep 111 and 112 .B /usr/5bin/posix/grep 113 accept the following options: 114 .TP 115 .B \-b 116 Each line is preceded by the block number on which it was found. 117 This is sometimes useful 118 in locating disk block numbers by context. 119 Block numbers start with 0. 120 .TP 121 .B \-c 122 Only a count of matching lines is printed. 123 .TP 124 .B \-h 125 Normally, the name of each input file is printed before a match 126 if there is more that one input file. 127 When this option is present, no file names are printed. 128 .TP 129 .B \-i 130 Upper- and lowercase differences are ignored when searching matches. 131 .TP 132 .B \-l 133 The names of files with matching lines are listed 134 (once) separated by newlines. 135 .TP 136 .B \-n 137 Each line is preceded by its line number in the file. 138 Line numbers start with 1. 139 .TP 140 .B \-s 141 Error messages for nonexistent or unreadable files are suppressed. 142 .TP 143 .B \-v 144 All lines but those matching are printed. 145 .PP 146 The following options are supported by 147 .B /usr/5bin/posix/grep 148 only: 149 .TP 150 .BI \-e\ pattern_list 151 Specifies one or more patterns, separated by newline characters. 152 A line is selected if one or more of the specified patterns are found. 153 .TP 154 .B \-E 155 All patterns are interpreted as extended regular expressions 156 as described in 157 .IR egrep (1). 158 .TP 159 .BI \-f\ pattern_file 160 One or more patterns, separated by newline 161 characters, are read from 162 .I pattern_file. 163 .TP 164 .B \-F 165 All patterns are interpreted as fixed strings, 166 as with 167 .IR fgrep (1). 168 .TP 169 .B \-q 170 Do not write anything to standard output. 171 .TP 172 .B \-x 173 Consider only lines consisting of the pattern as a whole, 174 like a regular expression surrounded by 175 .I ^ 176 and 177 .I $. 178 .PP 179 The following options are supported as extensions: 180 .TP 181 .B \-r 182 With this option given, 183 .I grep 184 does not directly search in each given file that is a directory, 185 but descends it recursively 186 and scans each regular file found below it. 187 Device files are ignored. 188 Symbolic links are followed. 189 .TP 190 .B \-R 191 Operates recursively as with the 192 .I \-r 193 option, 194 but does not follow symbolic links that point to directories 195 unless if they are explicitly specified as arguments. 196 .TP 197 .B \-w 198 Searches for the patterns treated as words, 199 as if they were surrounded by `\e<\ \e>'. 200 Only available if neither the 201 .I \-E 202 nor the 203 .I \-F 204 option are also supplied. 205 .TP 206 .B \-z 207 If an input file is found to be compressed with 208 .IR compress (1), 209 .IR gzip (1), 210 or 211 .IR bzip2 (1), 212 the appropriate compression program is started, 213 and 214 .I grep 215 searches for the pattern in its output. 216 .SH "ENVIRONMENT VARIABLES" 217 .TP 218 .BR LANG ", " LC_ALL 219 See 220 .IR locale (7). 221 .TP 222 .B LC_COLLATE 223 Affects the collation order for range expressions, 224 equivalence classes, and collation symbols 225 in basic regular expressions. 226 .TP 227 .B LC_CTYPE 228 Determines the mapping of bytes to characters 229 in both simple and basic regular expressions, 230 the availability and composition of character classes 231 in basic regular expressions, 232 and the case mapping for the 233 .B \-i 234 option. 235 .SH "SEE ALSO" 236 ed(1), 237 egrep(1), 238 fgrep(1), 239 sed(1), 240 locale(7) 241 .SH DIAGNOSTICS 242 Exit status is 0 if any matches are found, 243 1 if none, 2 for syntax errors or inaccessible files. 244 .SH NOTES 245 If a line contains a 246 .SM NUL 247 character, 248 only matches up to this character are found 249 (unless 250 .B /usr/5bin/posix/grep 251 is used with the 252 .I \-F 253 option). 254 The entire matching line will be printed. 255 .PP 256 The LC_COLLATE variable has currently no effect. 257 Ranges in bracket expressions are ordered 258 as byte values in single-byte locales 259 and as wide character values in multibyte locales; 260 equivalence classes match the given character only, 261 and multi-character collating elements are not available. 262 .PP 263 The options supported by 264 .B /usr/5bin/posix/grep 265 that are not accepted by 266 .B /usr/5bin/grep 267 can easily be replaced by portable constructs: 268 Use 269 .I egrep 270 instead of 271 .BR \-E , 272 .I fgrep 273 instead of 274 .BR \-F . 275 Use 276 .I egrep 277 if you need the 278 .B \-e 279 or 280 .B \-f 281 option, 282 use only one of them and that only once; 283 if necessary, use text processing tools 284 to generate a single expression list before. 285 Redirect standard output to 286 .I /dev/null 287 for 288 .B \-q 289 (the possible speedup with 290 .I \-q 291 is never worth human time spent with porting scripts), 292 and use the 293 .RI ` ^ ' 294 and 295 .RI ` $ ' 296 meta-characters instead of 297 .BR \-x .