1 2 3 4GREP(1) 10 GREP(1) 5 6 7NNAAMMEE 8 grep, egrep, fgrep - print lines matching a pattern 9 10SSYYNNOOPPOOSSIISS 11 ggrreepp [ --[[AABB] ]_n_u_m ] [ --[CCEEFFGGVVBBcchhiillnnssvvwwxx] ] [ --ee ] _p_a_t_t_e_r_n 12 | --ff_f_i_l_e ] [ _f_i_l_e_s... ] 13 14DDEESSCCRRIIPPTTIIOONN 15 GGrreepp searches the named input _f_i_l_e_s (or standard input if 16 no files are named, or the file name -- is given) for lines 17 containing a match to the given _p_a_t_t_e_r_n. By default, ggrreepp 18 prints the matching lines. 19 20 There are three major variants of ggrreepp, controlled by the 21 following options. 22 --GG Interpret _p_a_t_t_e_r_n as a basic regular expression 23 (see below). This is the default. 24 --EE Interpret _p_a_t_t_e_r_n as an extended regular expression 25 (see below). 26 --FF Interpret _p_a_t_t_e_r_n as a list of fixed strings, 27 separated by newlines, any of which is to be 28 matched. 29 In addition, two variant programs eeggrreepp and ffggrreepp are 30 available. EEggrreepp is similiar (but not identical) to 31 ggrreepp --EE, and is compatible with the historical Unix eeggrreepp. 32 FFggrreepp is the same as ggrreepp --FF. 33 34 All variants of ggrreepp understand the following options: 35 --_n_u_m Matches will be printed with _n_u_m lines of leading 36 and trailing context. However, ggrreepp will never 37 print any given line more than once. 38 --AA _n_u_m Print _n_u_m lines of trailing context after matching 39 lines. 40 --BB _n_u_m Print _n_u_m lines of leading context before matching 41 lines. 42 --CC Equivalent to --22. 43 --VV Print the version number of ggrreepp to standard error. 44 This version number should be included in all bug 45 reports (see below). 46 --bb Print the byte offset within the input file before 47 each line of output. 48 --cc Suppress normal output; instead print a count of 49 matching lines for each input file. With the --vv 50 option (see below), count non-matching lines. 51 --ee _p_a_t_t_e_r_n 52 Use _p_a_t_t_e_r_n as the pattern; useful to protect 53 patterns beginning with --. 54 --ff _f_i_l_e 55 Obtain the pattern from _f_i_l_e. 56 --hh Suppress the prefixing of filenames on output when 57 multiple files are searched. 58 --ii Ignore case distinctions in both the _p_a_t_t_e_r_n and 59 the input files. 60 --LL Suppress normal output; instead print the name of 61 62 63 64September 1992 1 65 66 67 68 69 70GREP(1) 10 GREP(1) 71 72 73 each input file from which no output would normally 74 have been printed. 75 --ll Suppress normal output; instead print the name of 76 each input file from which output would normally 77 have been printed. 78 --nn Prefix each line of output with the line number 79 within its input file. 80 --qq Quiet; suppress normal output. 81 --ss Suppress error messages about nonexistent or 82 unreadable files. 83 --vv Invert the sense of matching, to select non- 84 matching lines. 85 --ww Select only those lines containing matches that 86 form whole words. The test is that the matching 87 substring must either be at the beginning of the 88 line, or preceded by a non-word constituent 89 character. Similarly, it must be either at the end 90 of the line or followed by a non-word constituent 91 character. Word-constituent characters are 92 letters, digits, and the underscore. 93 --xx Select only those matches that exactly match the 94 whole line. 95 96RREEGGUULLAARR EEXXPPRREESSSSIIOONNSS 97 A regular expression is a pattern that describes a set of 98 strings. Regular expressions are constructed analagously 99 to arithmetic expressions, by using various operators to 100 combine smaller expressions. 101 102 GGrreepp understands two different versions of regular 103 expression syntax: ``basic'' and ``extended.'' In 104 GNU ggrreepp, there is no difference in available 105 functionality using either syntax. In other 106 implementations, basic regular expressions are less 107 powerful. The following description applies to extended 108 regular expressions; differences for basic regular 109 expressions are summarized afterwards. 110 111 The fundamental building blocks are the regular 112 expressions that match a single character. Most 113 characters, including all letters and digits, are regular 114 expressions that match themselves. Any metacharacter with 115 special meaning may be quoted by preceding it with a 116 backslash. 117 118 A list of characters enclosed by [[ and ]] matches any 119 single character in that list; if the first character of 120 the list is the caret ^^ then it matches any character _n_o_t 121 in the list. For example, the regular expression 122 [[00112233445566778899]] matches any single digit. A range of ASCII 123 characters may be specified by giving the first and last 124 characters, separated by a hyphen. Finally, certain named 125 classes of characters are predefined. Their names are 126 self explanatory, and they are [[::aallnnuumm::]], [[::aallpphhaa::]], 127 128 129 130September 1992 2 131 132 133 134 135 136GREP(1) 10 GREP(1) 137 138 139 [[::ccnnttrrll::]], [[::ddiiggiitt::]], [[::ggrraapphh::]], [[::lloowweerr::]], [[::pprriinntt::]], 140 [[::ppuunncctt::]], [[::ssppaaccee::]], [[::uuppppeerr::]], and [[::xxddiiggiitt::]].. For 141 example, [[[[::aallnnuumm::]]]] means [[00--99AA--ZZaa--zz]], except the latter 142 form is dependent upon the ASCII character encoding, 143 whereas the former is portable. (Note that the brackets 144 in these class names are part of the symbolic names, and 145 must be included in addition to the brackets delimiting 146 the bracket list.) Most metacharacters lose their special 147 meaning inside lists. To include a literal ]] place it 148 first in the list. Similarly, to include a literal ^^ 149 place it anywhere but first. Finally, to include a 150 literal -- place it last. 151 152 The period .. matches any single character. The symbol \\ww 153 is a synonym for [[[[::aallnnuumm::]]]] and \\WW is a synonym for 154 [[^^[[::aallnnuumm]]]]. 155 156 The caret ^^ and the dollar sign $$ are metacharacters that 157 respectively match the empty string at the beginning and 158 end of a line. The symbols \\<< and \\>> respectively match 159 the empty string at the beginning and end of a word. The 160 symbol \\bb matches the empty string at the edge of a word, 161 and \\BB matches the empty string provided it's _n_o_t at the 162 edge of a word. 163 164 A regular expression matching a single character may be 165 followed by one of several repetition operators: 166 ?? The preceding item is optional and matched at most 167 once. 168 ** The preceding item will be matched zero or more 169 times. 170 ++ The preceding item will be matched one or more 171 times. 172 {{_n}} The preceding item is matched exactly _n times. 173 {{_n,,}} The preceding item is matched _n or more times. 174 {{,,_m}} The preceding item is optional and is matched at 175 most _m times. 176 {{_n,,_m}} The preceding item is matched at least _n times, but 177 not more than _m times. 178 179 Two regular expressions may be concatenated; the resulting 180 regular expression matches any string formed by 181 concatenating two substrings that respectively match the 182 concatenated subexpressions. 183 184 Two regular expressions may be joined by the infix 185 operator ||; the resulting regular expression matches any 186 string matching either subexpression. 187 188 Repetition takes precedence over concatenation, which in 189 turn takes precedence over alternation. A whole 190 subexpression may be enclosed in parentheses to override 191 these precedence rules. 192 193 194 195 196September 1992 3 197 198 199 200 201 202GREP(1) 10 GREP(1) 203 204 205 The backreference \\_n, where _n is a single digit, matches 206 the substring previously matched by the _nth parenthesized 207 subexpression of the regular expression. 208 209 In basic regular expressions the metacharacters ??, ++, {{, 210 ||, ((, and )) lose their special meaning; instead use the 211 backslashed versions \\??, \\++, \\{{, \\||, \\((, and \\)). 212 213 In eeggrreepp the metacharacter {{ loses its special meaning; 214 instead use \\{{. 215 216DDIIAAGGNNOOSSTTIICCSS 217 Normally, exit status is 0 if matches were found, and 1 if 218 no matches were found. (The --vv option inverts the sense 219 of the exit status.) Exit status is 2 if there were 220 syntax errors in the pattern, inaccessible input files, or 221 other system errors. 222 223BBUUGGSS 224 Email bug reports to bbuugg--ggnnuu--uuttiillss@@pprreepp..aaii..mmiitt..eedduu. Be 225 sure to include the word ``grep'' somewhere in the 226 ``Subject:'' field. 227 228 Large repetition counts in the {{_m,,_n}} construct may cause 229 grep to use lots of memory. In addition, certain other 230 obscure regular expressions require exponential time and 231 space, and may cause ggrreepp to run out of memory. 232 233 Backreferences are very slow, and may require exponential 234 time. 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262September 1992 4 263 264 265