Print this page
8858 /usr/bin/grep doesn't support -E option
4580 /usr/bin/grep can't handle multibyte characters
8929 8868 tests are not delivered with system/test/utiltest
8860 Example in grep(1) is incorrect
Reviewed by: Peter Tribble <peter.tribble@gmail.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuripv@gmx.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/man/man1/grep.1.man.txt
          +++ new/usr/src/man/man1/grep.1.man.txt
   1    1  GREP(1)                          User Commands                         GREP(1)
   2    2  
   3    3  
   4    4  
   5    5  NAME
   6    6         grep - search a file for a pattern
   7    7  
   8    8  SYNOPSIS
   9      -       /usr/bin/grep [-c | -l |-q] [-r | -R] [-bHhinsvw]
  10      -           limited-regular-expression [filename]...
  11      -
  12      -
  13      -       /usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-r | -R]
        9 +       /usr/bin/grep [-E | -F] [-c | -l | -q] [-r | -R]
  14   10             [-bHhinsvwx] [-A number] [-B number] [-C number | -number] -e pattern_list... [-f pattern_file]...
  15   11             [file]...
  16   12  
  17   13  
  18      -       /usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-r | -R]
       14 +       /usr/bin/grep [-E | -F] [-c | -l | -q] [-r | -R]
  19   15             [-bHhinsvwx] [-A number] [-B number] [-C number | -number] [-e pattern_list]... -f pattern_file...
  20   16             [file]...
  21   17  
  22   18  
  23      -       /usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-r | -R]
       19 +       /usr/bin/grep [-E | -F] [-c | -l | -q] [-r | -R]
  24   20             [-bHhinsvwx] [-A number] [-B number] [-C number | -number] pattern [file]...
  25   21  
  26   22  
  27   23  DESCRIPTION
  28   24         The grep utility searches text files for a pattern and prints all lines
  29   25         that contain that pattern.  It uses a compact non-deterministic
  30   26         algorithm.
  31   27  
  32   28  
  33   29         Be careful using the characters $, *, [, ^, |, (, ), and \ in the
  34   30         pattern_list because they are also meaningful to the shell. It is
  35   31         safest to enclose the entire pattern_list in single quotes '...'.
  36   32  
  37   33  
  38   34         If no files are specified, grep assumes standard input. Normally, each
  39   35         line found is copied to standard output. The file name is printed
  40   36         before each line found if there is more than one input file.
  41   37  
  42      -   /usr/bin/grep
  43      -       The /usr/bin/grep utility uses limited regular expressions like those
  44      -       described on the regexp(5) manual page to match the patterns.
  45      -
  46      -   /usr/xpg4/bin/grep
  47      -       The options -E and -F affect the way /usr/xpg4/bin/grep interprets
  48      -       pattern_list. If -E is specified, /usr/xpg4/bin/grep interprets
  49      -       pattern_list as a full regular expression (see -E for description).  If
  50      -       -F is specified, grep interprets pattern_list as a fixed string. If
  51      -       neither are specified, grep interprets pattern_list as a basic regular
  52      -       expression as described on regex(5) manual page.
       38 +       The options -E and -F affect the way grep interprets pattern_list. If
       39 +       -E is specified, grep interprets pattern_list as a full regular
       40 +       expression (see -E for description).  If -F is specified, grep
       41 +       interprets pattern_list as a fixed string. If neither are specified,
       42 +       grep interprets pattern_list as a basic regular expression as described
       43 +       on regex(5) manual page.
  53   44  
  54   45  OPTIONS
  55      -       The following options are supported for both /usr/bin/grep and
  56      -       /usr/xpg4/bin/grep:
       46 +       The following options are supported:
       47 +
       48 +       -A number
       49 +             Prints number input lines of context after each matching line. If
       50 +             there are multiple matching lines, their context lines are
       51 +             separated by a -- delimiter line.
       52 +
  57   53  
  58   54         -b
  59   55               Precedes each line by the block number on which it was found.
  60   56               This can be useful in locating block numbers by context (first
  61   57               block is 0).
  62   58  
  63   59  
       60 +       -B number
       61 +             Prints number input lines of context before each matching line.
       62 +             If there are multiple matching lines, their context lines are
       63 +             separated by a -- delimiter line.
       64 +
       65 +
  64   66         -c
  65   67               Prints only a count of the lines that contain the pattern.
  66   68  
  67   69  
  68   70         -H
  69   71               Precedes each line by the name of the file containing the
  70   72               matching line.
  71   73  
  72   74  
       75 +       -e pattern_list
       76 +             Specifies one or more patterns to be used during the search for
       77 +             input. Patterns in pattern_list must be separated by a NEWLINE
       78 +             character. A null pattern can be specified by two adjacent
       79 +             newline characters in pattern_list.  Unless the -E or -F option
       80 +             is also specified, each pattern is treated as a basic regular
       81 +             expression.  Multiple -e and -f options are accepted by grep. All
       82 +             of the specified patterns are used when matching lines, but the
       83 +             order of evaluation is unspecified.
       84 +
       85 +
       86 +       -E
       87 +             Matches using full regular expressions. Treats each pattern
       88 +             specified as a full regular expression. If any entire full
       89 +             regular expression pattern matches an input line, the line is
       90 +             matched. A null full regular expression matches every line. Each
       91 +             pattern is interpreted as a full regular expression as described
       92 +             on the regex(5) manual page, except for \( and \), and including:
       93 +
       94 +                 1.     A full regular expression followed by + that matches
       95 +                        one or more occurrences of the full regular
       96 +                        expression.
       97 +
       98 +                 2.     A full regular expression followed by ? that matches 0
       99 +                        or 1 occurrences of the full regular expression.
      100 +
      101 +                 3.     Full regular expressions separated by | or by a new-
      102 +                        line that match strings that are matched by any of the
      103 +                        expressions.
      104 +
      105 +                 4.     A full regular expression that is enclosed in
      106 +                        parentheses () for grouping.
      107 +             The order of precedence of operators is [], then *?+, then
      108 +             concatenation, then | and new-line.
      109 +
      110 +
      111 +       -f pattern_file
      112 +             Reads one or more patterns from the file named by the path name
      113 +             pattern_file. Patterns in pattern_file are terminated by a
      114 +             NEWLINE character. A null pattern can be specified by an empty
      115 +             line in pattern_file. Unless the -E or -F option is also
      116 +             specified, each pattern is treated as a basic regular expression.
      117 +
      118 +
      119 +       -F
      120 +             Matches using fixed strings. Treats each pattern specified as a
      121 +             string instead of a regular expression. If an input line contains
      122 +             any of the patterns as a contiguous sequence of bytes, the line
      123 +             is matched. A null string matches every line. See fgrep(1) for
      124 +             more information.
      125 +
      126 +
  73  127         -h
  74  128               Prevents the name of the file containing the matching line from
  75  129               being prepended to that line.  Used when searching multiple
  76  130               files.
  77  131  
  78  132  
  79  133         -i
  80  134               Ignores upper/lower case distinction during comparisons.
  81  135  
  82  136  
↓ open down ↓ 18 lines elided ↑ open up ↑
 101  155               Read all files under each directory, recursively, following all
 102  156               symbolic links.
 103  157  
 104  158  
 105  159         -q
 106  160               Quiet. Does not write anything to the standard output, regardless
 107  161               of matching lines. Exits with zero status if an input line is
 108  162               selected.
 109  163  
 110  164  
      165 +       -number
      166 +       -C number
      167 +             Prints number input lines of context before and number input
      168 +             lines of context after each matching line. If there are multiple
      169 +             matching lines, their context lines are separated by a --
      170 +             delimiter line.
      171 +
      172 +
 111  173         -s
 112  174               Suppresses error messages about nonexistent or unreadable files.
 113  175  
 114  176  
 115  177         -v
 116  178               Prints all lines except those that contain the pattern.
 117  179  
 118  180  
 119  181         -w
 120  182               Searches for the expression as a word as if surrounded by \< and
 121  183               \>.
 122  184  
 123  185  
 124      -   /usr/xpg4/bin/grep
 125      -       The following options are supported for /usr/xpg4/bin/grep only:
 126      -
 127      -       -A number
 128      -                          Prints number input lines of context after each
 129      -                          matching line. If there are multiple matching lines,
 130      -                          their context lines are separated by a -- delimiter
 131      -                          line.
 132      -
 133      -
 134      -       -B number
 135      -                          Prints number input lines of context before each
 136      -                          matching line. If there are multiple matching lines,
 137      -                          their context lines are separated by a -- delimiter
 138      -                          line.
 139      -
 140      -
 141      -       -number
 142      -       -C number
 143      -                          Prints number input lines of context before and
 144      -                          number input lines of context after each matching
 145      -                          line. If there are multiple matching lines, their
 146      -                          context lines are separated by a -- delimiter line.
 147      -
 148      -
 149      -
 150      -       -e pattern_list
 151      -                          Specifies one or more patterns to be used during the
 152      -                          search for input. Patterns in pattern_list must be
 153      -                          separated by a NEWLINE character. A null pattern can
 154      -                          be specified by two adjacent newline characters in
 155      -                          pattern_list.  Unless the -E or -F option is also
 156      -                          specified, each pattern is treated as a basic
 157      -                          regular expression.  Multiple -e and -f options are
 158      -                          accepted by grep. All of the specified patterns are
 159      -                          used when matching lines, but the order of
 160      -                          evaluation is unspecified.
 161      -
 162      -
 163      -       -E
 164      -                          Matches using full regular expressions. Treats each
 165      -                          pattern specified as a full regular expression. If
 166      -                          any entire full regular expression pattern matches
 167      -                          an input line, the line is matched. A null full
 168      -                          regular expression matches every line. Each pattern
 169      -                          is interpreted as a full regular expression as
 170      -                          described on the regex(5) manual page, except for \(
 171      -                          and \), and including:
 172      -
 173      -                              1.     A full regular expression followed by +
 174      -                                     that matches one or more occurrences of
 175      -                                     the full regular expression.
 176      -
 177      -                              2.     A full regular expression followed by ?
 178      -                                     that matches 0 or 1 occurrences of the
 179      -                                     full regular expression.
 180      -
 181      -                              3.     Full regular expressions separated by |
 182      -                                     or by a new-line that match strings that
 183      -                                     are matched by any of the expressions.
 184      -
 185      -                              4.     A full regular expression that is
 186      -                                     enclosed in parentheses () for grouping.
 187      -                          The order of precedence of operators is [], then
 188      -                          *?+, then concatenation, then | and new-line.
 189      -
 190      -
 191      -       -f pattern_file
 192      -                          Reads one or more patterns from the file named by
 193      -                          the path name pattern_file. Patterns in pattern_file
 194      -                          are terminated by a NEWLINE character. A null
 195      -                          pattern can be specified by an empty line in
 196      -                          pattern_file. Unless the -E or -F option is also
 197      -                          specified, each pattern is treated as a basic
 198      -                          regular expression.
 199      -
 200      -
 201      -       -F
 202      -                          Matches using fixed strings. Treats each pattern
 203      -                          specified as a string instead of a regular
 204      -                          expression. If an input line contains any of the
 205      -                          patterns as a contiguous sequence of bytes, the line
 206      -                          is matched. A null string matches every line. See
 207      -                          fgrep(1) for more information.
 208      -
 209      -
 210  186         -x
 211      -                          Considers only input lines that use all characters
 212      -                          in the line to match an entire fixed string or
 213      -                          regular expression to be matching lines.
      187 +             Considers only input lines that use all characters in the line to
      188 +             match an entire fixed string or regular expression to be matching
      189 +             lines.
 214  190  
 215  191  
 216  192  OPERANDS
 217  193         The following operands are supported:
 218  194  
 219  195         file
 220  196                 A path name of a file to be searched for the patterns. If no
 221  197                 file operands are specified, the standard input is used.
 222  198  
 223      -
 224      -   /usr/bin/grep
 225      -       pattern
 226      -                  Specifies a pattern to be used during the search for input.
 227      -
 228      -
 229      -   /usr/xpg4/bin/grep
 230  199         pattern
 231      -                  Specifies one or more patterns to be used during the search
 232      -                  for input. This operand is treated as if it were specified
 233      -                  as -e pattern_list.
      200 +               Specifies one or more patterns to be used during the search for
      201 +               input. This operand is treated as if it were specified as -e
      202 +               pattern_list.
 234  203  
 235  204  
 236  205  USAGE
 237  206         The -e pattern_list option has the same effect as the pattern_list
 238  207         operand, but is useful when pattern_list begins with the hyphen
 239  208         delimiter. It is also useful when it is more convenient to provide
 240  209         multiple patterns as separate arguments.
 241  210  
 242  211  
 243  212         Multiple -e and -f options are accepted and grep uses all of the
↓ open down ↓ 45 lines elided ↑ open up ↑
 289  258  
 290  259  
 291  260  
 292  261         Example 3 Finding Lines Containing Strings
 293  262  
 294  263  
 295  264         All of the following commands print all lines containing strings abc or
 296  265         def or both:
 297  266  
 298  267  
 299      -         example% /usr/xpg4/bin/grep 'abc
      268 +         example% /usr/bin/grep 'abc
 300  269           def'
 301      -         example% /usr/xpg4/bin/grep -e 'abc
      270 +         example% /usr/bin/grep -e 'abc
 302  271           def'
 303      -         example% /usr/xpg4/bin/grep -e 'abc' -e 'def'
 304      -         example% /usr/xpg4/bin/grep -E 'abc|def'
 305      -         example% /usr/xpg4/bin/grep -E -e 'abc|def'
 306      -         example% /usr/xpg4/bin/grep -E -e 'abc' -e 'def'
 307      -         example% /usr/xpg4/bin/grep -E 'abc
      272 +         example% /usr/bin/grep -e 'abc' -e 'def'
      273 +         example% /usr/bin/grep -E 'abc|def'
      274 +         example% /usr/bin/grep -E -e 'abc|def'
      275 +         example% /usr/bin/grep -E -e 'abc' -e 'def'
      276 +         example% /usr/bin/grep -E 'abc
 308  277           def'
 309      -         example% /usr/xpg4/bin/grep -E -e 'abc
      278 +         example% /usr/bin/grep -E -e 'abc
 310  279           def'
 311      -         example% /usr/xpg4/bin/grep -F -e 'abc' -e 'def'
 312      -         example% /usr/xpg4/bin/grep -F 'abc
      280 +         example% /usr/bin/grep -F -e 'abc' -e 'def'
      281 +         example% /usr/bin/grep -F 'abc
 313  282           def'
 314      -         example% /usr/xpg4/bin/grep -F -e 'abc
      283 +         example% /usr/bin/grep -F -e 'abc
 315  284           def'
 316  285  
 317  286  
 318  287  
 319  288         Example 4 Finding Lines with Matching Strings
 320  289  
 321  290  
 322  291         Both of the following commands print all lines matching exactly abc or
 323  292         def:
 324  293  
 325  294  
 326      -         example% /usr/xpg4/bin/grep -E '^abc$ ^def$'
 327      -         example% /usr/xpg4/bin/grep -F -x 'abc def'
      295 +         example% /usr/bin/grep -E '^abc$
      296 +         ^def$'
      297 +         example% /usr/bin/grep -F -x 'abc
      298 +         def'
 328  299  
 329  300  
 330  301  
 331  302  ENVIRONMENT VARIABLES
 332  303         See environ(5) for descriptions of the following environment variables
 333  304         that affect the execution of grep: LANG, LC_ALL, LC_COLLATE, LC_CTYPE,
 334  305         LC_MESSAGES, and NLSPATH.
 335  306  
 336  307  EXIT STATUS
 337  308         The following exit values are returned:
↓ open down ↓ 6 lines elided ↑ open up ↑
 344  315              No matches were found.
 345  316  
 346  317  
 347  318         2
 348  319              Syntax errors or inaccessible files (even if matches were found).
 349  320  
 350  321  
 351  322  ATTRIBUTES
 352  323         See attributes(5) for descriptions of the following attributes:
 353  324  
 354      -   /usr/bin/grep
 355      -
 356      -       +---------------+-----------------+
 357      -       |ATTRIBUTE TYPE | ATTRIBUTE VALUE |
 358      -       +---------------+-----------------+
 359      -       |CSI            | Not Enabled     |
 360      -       +---------------+-----------------+
 361      -
 362      -   /usr/xpg4/bin/grep
 363  325  
 364  326         +--------------------+-------------------+
 365  327         |  ATTRIBUTE TYPE    |  ATTRIBUTE VALUE  |
 366  328         +--------------------+-------------------+
 367  329         |CSI                 | Enabled           |
 368  330         +--------------------+-------------------+
 369  331         |Interface Stability | Committed         |
 370  332         +--------------------+-------------------+
 371  333         |Standard            | See standards(5). |
 372  334         +--------------------+-------------------+
 373  335  
 374  336  SEE ALSO
 375  337         egrep(1), fgrep(1), sed(1), sh(1), attributes(5), environ(5),
 376  338         largefile(5), regex(5), regexp(5), standards(5)
 377  339  
 378  340  NOTES
 379      -   /usr/bin/grep
 380      -       Lines are limited only by the size of the available virtual memory. If
 381      -       there is a line with embedded nulls, grep only matches up to the first
 382      -       null. If the line matches, the entire line is printed.
 383      -
 384      -   /usr/xpg4/bin/grep
 385  341         The results are unspecified if input files contain lines longer than
 386  342         LINE_MAX bytes or contain binary data. LINE_MAX is defined in
 387  343         /usr/include/limits.h.
 388  344  
      345 +       In the past the behavior of /usr/xpg4/bin/grep and /usr/bin/grep
      346 +       utilities was different. Now /usr/bin/grep is replaced by
      347 +       /usr/xpg4/bin/grep.
      348 +
 389  349  
 390  350  
 391      -                                 June 5, 2017                          GREP(1)
      351 +                               November 28, 2017                       GREP(1)
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX