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>
   1 EGREP(1)                         User Commands                        EGREP(1)
   2 
   3 
   4 
   5 NAME
   6        egrep - search a file for a pattern using full regular expressions
   7 
   8 SYNOPSIS
   9        /usr/bin/egrep [-bcHhilnqsv] -e pattern_list [file...]
  10 
  11 
  12        /usr/bin/egrep [-bcHhilnqsv] -f file [file...]
  13 
  14 
  15        /usr/bin/egrep [-bcHhilnqsv] pattern [file...]
  16 
  17 
  18        /usr/xpg4/bin/egrep [-bcHhilnqsvx] -e pattern_list [-f file]
  19             [file...]
  20 
  21 
  22        /usr/xpg4/bin/egrep [-bcHhilnqsvx] [-e pattern_list] -f file
  23             [file...]
  24 
  25 
  26        /usr/xpg4/bin/egrep [-bcHhilnqsvx] pattern [file...]
  27 
  28 
  29 DESCRIPTION
  30        The egrep (expression grep) utility searches files for a pattern of
  31        characters and prints all lines that contain that pattern. egrep uses
  32        full regular expressions (expressions that have string values that use
  33        the full set of alphanumeric and special characters) to match the
  34        patterns. It uses a fast deterministic algorithm that sometimes needs
  35        exponential space.
  36 
  37 
  38        If no files are specified, egrep assumes standard input. Normally, each
  39        line found is copied to the standard output. The file name is printed
  40        before each line found if there is more than one input file.
  41 
  42    /usr/bin/egrep
  43        The /usr/bin/egrep utility accepts full regular expressions as
  44        described on the regexp(5) manual page, except for \( and \), \( and
  45        \), \{ and \}, \< and \>, and \n, and with the addition of:
  46 
  47            1.     A full regular expression followed by + that matches one or
  48                   more occurrences of the full regular expression.
  49 
  50            2.     A full regular expression followed by ? that matches 0 or 1
  51                   occurrences of the full regular expression.
  52 
  53            3.     Full regular expressions separated by | or by a NEWLINE that
  54                   match strings that are matched by any of the expressions.
  55 
  56            4.     A full regular expression that can be enclosed in
  57                   parentheses ()for grouping.
  58 
  59 
  60        Be careful using the characters $, *, [, ^, |, (, ), and \ in full
  61        regular expression, because they are also meaningful to the shell. It
  62        is safest to enclose the entire full regular expression in single
  63        quotes (a'a').
  64 
  65 
  66        The order of precedence of operators is [], then *?+, then
  67        concatenation, then | and NEWLINE.
  68 
  69    /usr/xpg4/bin/egrep
  70        The /usr/xpg4/bin/egrep utility uses the regular expressions described
  71        in the EXTENDED REGULAR EXPRESSIONS section of the regex(5) manual
  72        page.
  73 
  74 OPTIONS
  75        The following options are supported for both /usr/bin/egrep and
  76        /usr/xpg4/bin/egrep:
  77 
  78        -b
  79                           Precede each line by the block number on which it
  80                           was found. This can be useful in locating block
  81                           numbers by context (first block is 0).
  82 
  83 
  84        -c
  85                           Print only a count of the lines that contain the
  86                           pattern.
  87 
  88 
  89        -e pattern_list
  90                           Search for a pattern_list (full regular expression
  91                           that begins with a -).
  92 
  93 
  94        -f file
  95                           Take the list of full regular expressions from file.
  96 
  97 
  98        -H
  99                           Precedes each line by the name of the file
 100                           containing the matching line.
 101 
 102 
 103        -h
 104                           Suppress printing of filenames when searching
 105                           multiple files.
 106 
 107 
 108        -i
 109                           Ignore upper/lower case distinction during
 110                           comparisons.
 111 
 112 
 113        -l
 114                           Print the names of files with matching lines once,
 115                           separated by NEWLINEs. Does not repeat the names of
 116                           files when the pattern is found more than once.
 117 
 118 
 119        -n
 120                           Precede each line by its line number in the file
 121                           (first line is 1).
 122 
 123 
 124        -q
 125                           Quiet. Does not write anything to the standard
 126                           output, regardless of matching lines. Exits with
 127                           zero status if an input line is selected.
 128 
 129 
 130        -s
 131                           Legacy equivalent of -q.
 132 
 133 
 134        -v
 135                           Print all lines except those that contain the
 136                           pattern.
 137 
 138 
 139    /usr/xpg4/bin/egrep
 140        The following options are supported for /usr/xpg4/bin/egrep only:
 141 
 142        -x
 143              Consider only input lines that use all characters in the line to
 144              match an entire fixed string or regular expression to be matching
 145              lines.
 146 
 147 
 148 OPERANDS
 149        The following operands are supported:
 150 
 151        file
 152                A path name of a file to be searched for the patterns. If no
 153                file operands are specified, the standard input is used.
 154 
 155 
 156    /usr/bin/egrep
 157        pattern
 158                   Specify a pattern to be used during the search for input.
 159 
 160 
 161    /usr/xpg4/bin/egrep
 162        pattern
 163                   Specify one or more patterns to be used during the search
 164                   for input. This operand is treated as if it were specified
 165                   as -epattern_list..
 166 
 167 
 168 USAGE
 169        See largefile(5) for the description of the behavior of egrep when
 170        encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
 171 
 172 ENVIRONMENT VARIABLES
 173        See environ(5) for descriptions of the following environment variables
 174        that affect the execution of egrep: LC_COLLATE, LC_CTYPE, LC_MESSAGES,
 175        and NLSPATH.
 176 
 177 EXIT STATUS
 178        The following exit values are returned:
 179 
 180        0
 181             If any matches are found.
 182 
 183 
 184        1
 185             If no matches are found.
 186 
 187 
 188        2
 189             For syntax errors or inaccessible files (even if matches were
 190             found).
 191 
 192 
 193 ATTRIBUTES
 194        See attributes(5) for descriptions of the following attributes:
 195 
 196    /usr/bin/egrep
 197 
 198        +---------------+-----------------+
 199        |ATTRIBUTE TYPE | ATTRIBUTE VALUE |
 200        +---------------+-----------------+
 201        |CSI            | Not Enabled     |
 202        +---------------+-----------------+
 203 
 204    /usr/xpg4/bin/egrep
 205 
 206        +---------------+-----------------+
 207        |ATTRIBUTE TYPE | ATTRIBUTE VALUE |
 208        +---------------+-----------------+
 209        |CSI            | Enabled         |
 210        +---------------+-----------------+
 211 
 212 SEE ALSO
 213        fgrep(1), grep(1), sed(1), sh(1), attributes(5), environ(5),
 214        largefile(5), regex(5), regexp(5), XPG4(5)
 215 
 216 NOTES
 217        Ideally there should be only one grep command, but there is not a
 218        single algorithm that spans a wide enough range of space-time trade-
 219        offs.
 220 
 221 
 222        Lines are limited only by the size of the available virtual memory.
 223 
 224    /usr/xpg4/bin/egrep
 225        The /usr/xpg4/bin/egrep utility is identical to /usr/xpg4/bin/grep -E.
 226        See grep(1). Portable applications should use /usr/xpg4/bin/grep -E.



 227 
 228 
 229 
 230                                   May 3, 2013                         EGREP(1)
   1 EGREP(1)                         User Commands                        EGREP(1)
   2 
   3 
   4 
   5 NAME
   6        egrep - search a file for a pattern using full regular expressions
   7 
   8 SYNOPSIS
   9        /usr/bin/egrep [-bcHhilnqsvx] -e pattern_list [-f file]









  10             [file...]
  11 
  12 
  13        /usr/bin/egrep [-bcHhilnqsvx] [-e pattern_list] -f file
  14             [file...]
  15 
  16 
  17        /usr/bin/egrep [-bcHhilnqsvx] pattern [file...]
  18 
  19 
  20 DESCRIPTION
  21        The egrep (expression grep) utility searches files for a pattern of
  22        characters and prints all lines that contain that pattern. egrep uses
  23        full regular expressions (expressions that have string values that use
  24        the full set of alphanumeric and special characters) to match the
  25        patterns. It uses a fast deterministic algorithm that sometimes needs
  26        exponential space.
  27 
  28 
  29        If no files are specified, egrep assumes standard input. Normally, each
  30        line found is copied to the standard output. The file name is printed
  31        before each line found if there is more than one input file.
  32 
  33        The egrep utility accepts the same form of full regular expressions as
  34        grep(1) -E option.














  35 
  36 
  37        Be careful using the characters $, *, [, ^, |, (, ), and \ in full
  38        regular expression, because they are also meaningful to the shell. It
  39        is safest to enclose the entire full regular expression in single
  40        quotes (a'a').
  41 
  42 
  43        The order of precedence of operators is [], then *?+, then
  44        concatenation, then | and NEWLINE.
  45 





  46 OPTIONS
  47        The following options are supported:

  48 
  49        -b
  50              Precede each line by the block number on which it was found. This
  51              can be useful in locating block numbers by context (first block
  52              is 0).
  53 
  54 
  55        -c
  56              Print only a count of the lines that contain the pattern.

  57 
  58 
  59        -e pattern_list
  60              Search for a pattern_list (full regular expression that begins
  61              with a -).
  62 
  63 
  64        -f file
  65              Take the list of full regular expressions from file.
  66 
  67 
  68        -H
  69              Precedes each line by the name of the file containing the
  70              matching line.
  71 
  72 
  73        -h
  74              Suppress printing of filenames when searching multiple files.

  75 
  76 
  77        -i
  78              Ignore upper/lower case distinction during comparisons.

  79 
  80 
  81        -l
  82              Print the names of files with matching lines once, separated by
  83              NEWLINEs. Does not repeat the names of files when the pattern is
  84              found more than once.
  85 
  86 
  87        -n
  88              Precede each line by its line number in the file (first line is
  89              1).
  90 
  91 
  92        -q
  93              Quiet. Does not write anything to the standard output, regardless
  94              of matching lines. Exits with zero status if an input line is
  95              selected.
  96 
  97 
  98        -s
  99              Legacy equivalent of -q.
 100 
 101 
 102        -v
 103              Print all lines except those that contain the pattern.


 104 


 105 
 106        -x
 107              Consider only input lines that use all characters in the line to
 108              match an entire fixed string or regular expression to be matching
 109              lines.
 110 
 111 
 112 OPERANDS
 113        The following operands are supported:
 114 
 115        file
 116                A path name of a file to be searched for the patterns. If no
 117                file operands are specified, the standard input is used.
 118 


 119        pattern
 120                Specify one or more patterns to be used during the search for
 121                input. This operand is treated as if it were specified as
 122                -epattern_list.





 123 
 124 
 125 USAGE
 126        See largefile(5) for the description of the behavior of egrep when
 127        encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
 128 
 129 ENVIRONMENT VARIABLES
 130        See environ(5) for descriptions of the following environment variables
 131        that affect the execution of egrep: LC_COLLATE, LC_CTYPE, LC_MESSAGES,
 132        and NLSPATH.
 133 
 134 EXIT STATUS
 135        The following exit values are returned:
 136 
 137        0
 138             If any matches are found.
 139 
 140 
 141        1
 142             If no matches are found.
 143 
 144 
 145        2
 146             For syntax errors or inaccessible files (even if matches were
 147             found).
 148 
 149 
 150 ATTRIBUTES
 151        See attributes(5) for descriptions of the following attributes:
 152 







 153 

 154 
 155        +---------------+-----------------+
 156        |ATTRIBUTE TYPE | ATTRIBUTE VALUE |
 157        +---------------+-----------------+
 158        |CSI            | Enabled         |
 159        +---------------+-----------------+
 160 
 161 SEE ALSO
 162        fgrep(1), grep(1), sed(1), sh(1), attributes(5), environ(5),
 163        largefile(5), regex(5), regexp(5), XPG4(5)
 164 
 165 NOTES
 166        Ideally there should be only one grep command, but there is not a
 167        single algorithm that spans a wide enough range of space-time trade-
 168        offs.
 169 
 170 
 171        Lines are limited only by the size of the available virtual memory.
 172 
 173        The /usr/bin/egrep utility is identical to /usr/bin/grep -E. See
 174        grep(1). Portable applications should use /usr/bin/grep -E.
 175 
 176        In the past the behavior of /usr/xpg4/bin/egrep and /usr/bin/egrep
 177        utilities was different. Now /usr/bin/egrep is replaced by
 178        /usr/xpg4/bin/egrep.
 179 
 180 
 181 
 182                                November 28, 2017                      EGREP(1)