GREP(1)                    POSIX Programmer's Manual                   GREP(1)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       grep -- search a file for a pattern

SSYYNNOOPPSSIISS
       grep [[-E|-F]] [[-c|-l|-q]] [[-insvx]] -e _p_a_t_t_e_r_n___l_i_s_t
           [[-e _p_a_t_t_e_r_n___l_i_s_t]]... [[-f _p_a_t_t_e_r_n___f_i_l_e]]... [[_f_i_l_e...]]

       grep [[-E|-F]] [[-c|-l|-q]] [[-insvx]] [[-e _p_a_t_t_e_r_n___l_i_s_t]]......
           -f _p_a_t_t_e_r_n___f_i_l_e [[-f _p_a_t_t_e_r_n___f_i_l_e]]... [[_f_i_l_e...]]

       grep [[-E|-F]] [[-c|-l|-q]] [[-insvx]] _p_a_t_t_e_r_n___l_i_s_t [[_f_i_l_e...]]

DDEESSCCRRIIPPTTIIOONN
       The _g_r_e_p utility shall search the input files, selecting lines matching
       one or more patterns; the types of patterns are controlled by the
       options specified. The patterns are specified by the --ee option, --ff
       option, or the _p_a_t_t_e_r_n___l_i_s_t operand. The _p_a_t_t_e_r_n___l_i_s_t's value shall
       consist of one or more patterns separated by <newline> characters; the
       _p_a_t_t_e_r_n___f_i_l_e's contents shall consist of one or more patterns
       terminated by a <newline> character. By default, an input line shall be
       selected if any pattern, treated as an entire basic regular expression
       (BRE) as described in the Base Definitions volume of POSIX.1-2008,
       _S_e_c_t_i_o_n _9_._3, _B_a_s_i_c _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s, matches any part of the line
       excluding the terminating <newline>; a null BRE shall match every line.
       By default, each selected input line shall be written to the standard
       output.

       Regular expression matching shall be based on text lines. Since a
       <newline> separates or terminates patterns (see the --ee and --ff options
       below), regular expressions cannot contain a <newline>.  Similarly,
       since patterns are matched against individual lines (excluding the
       terminating <newline> characters) of the input, there is no way for a
       pattern to match a <newline> found in the input.

OOPPTTIIOONNSS
       The _g_r_e_p utility shall conform to the Base Definitions volume of
       POSIX.1-2008, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s.

       The following options shall be supported:

       --EE        Match using extended regular expressions.  Treat each pattern
                 specified as an ERE, as described in the Base Definitions
                 volume of POSIX.1-2008, _S_e_c_t_i_o_n _9_._4, _E_x_t_e_n_d_e_d _R_e_g_u_l_a_r
                 _E_x_p_r_e_s_s_i_o_n_s.  If any entire ERE pattern matches some part of
                 an input line excluding the terminating <newline>, the line
                 shall be matched. A null ERE shall match every line.

       --FF        Match using fixed strings. Treat each pattern specified as a
                 string instead of a regular expression. If an input line
                 contains any of the patterns as a contiguous sequence of
                 bytes, the line shall be matched.  A null string shall match
                 every line.

       --cc        Write only a count of selected lines to standard output.

       --ee _p_a_t_t_e_r_n___l_i_s_t
                 Specify one or more patterns to be used during the search for
                 input.  The application shall ensure that patterns in
                 _p_a_t_t_e_r_n___l_i_s_t are separated by a <newline>.  A null pattern
                 can be specified by two adjacent <newline> characters in
                 _p_a_t_t_e_r_n___l_i_s_t.  Unless the --EE or --FF option is also specified,
                 each pattern shall be treated as a BRE, as described in the
                 Base Definitions volume of POSIX.1-2008, _S_e_c_t_i_o_n _9_._3, _B_a_s_i_c
                 _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s.  Multiple --ee and --ff options shall be
                 accepted by the _g_r_e_p utility. All of the specified patterns
                 shall be used when matching lines, but the order of
                 evaluation is unspecified.

       --ff _p_a_t_t_e_r_n___f_i_l_e
                 Read one or more patterns from the file named by the pathname
                 _p_a_t_t_e_r_n___f_i_l_e.  Patterns in _p_a_t_t_e_r_n___f_i_l_e shall be terminated
                 by a <newline>.  A null pattern can be specified by an empty
                 line in _p_a_t_t_e_r_n___f_i_l_e.  Unless the --EE or --FF option is also
                 specified, each pattern shall be treated as a BRE, as
                 described in the Base Definitions volume of POSIX.1-2008,
                 _S_e_c_t_i_o_n _9_._3, _B_a_s_i_c _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s.

       --ii        Perform pattern matching in searches without regard to case;
                 see the Base Definitions volume of POSIX.1-2008, _S_e_c_t_i_o_n _9_._2,
                 _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n _G_e_n_e_r_a_l _R_e_q_u_i_r_e_m_e_n_t_s.

       --ll        (The letter ell.) Write only the names of files containing
                 selected lines to standard output. Pathnames shall be written
                 once per file searched. If the standard input is searched, a
                 pathname of ""((ssttaannddaarrddinput)" shall be written, in the POSIX
                 locale. In other locales, ""ssttaannddaarrddinput" may be replaced by
                 something more appropriate in those locales.

       --nn        Precede each output line by its relative line number in the
                 file, each file starting at line 1. The line number counter
                 shall be reset for each file processed.

       --qq        Quiet. Nothing shall be written to the standard output,
                 regardless of matching lines. Exit with zero status if an
                 input line is selected.

       --ss        Suppress the error messages ordinarily written for
                 nonexistent or unreadable files. Other error messages shall
                 not be suppressed.

       --vv        Select lines not matching any of the specified patterns. If
                 the --vv option is not specified, selected lines shall be those
                 that match any of the specified patterns.

       --xx        Consider only input lines that use all characters in the line
                 excluding the terminating <newline> to match an entire fixed
                 string or regular expression to be matching lines.

OOPPEERRAANNDDSS
       The following operands shall be supported:

       _p_a_t_t_e_r_n___l_i_s_t
                 Specify one or more patterns to be used during the search for
                 input.  This operand shall be treated as if it were specified
                 as --ee _p_a_t_t_e_r_n___l_i_s_t.

       _f_i_l_e      A pathname of a file to be searched for the patterns. If no
                 _f_i_l_e operands are specified, the standard input shall be
                 used.

SSTTDDIINN
       The standard input shall be used if no _f_i_l_e operands are specified, and
       shall be used if a _f_i_l_e operand is ''--'' and the implementation treats
       the ''--'' as meaning standard input.  Otherwise, the standard input shall
       not be used.  See the INPUT FILES section.

IINNPPUUTT FFIILLEESS
       The input files shall be text files.

EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
       The following environment variables shall affect the execution of _g_r_e_p:

       _L_A_N_G      Provide a default value for the internationalization
                 variables that are unset or null. (See the Base Definitions
                 volume of POSIX.1-2008, _S_e_c_t_i_o_n _8_._2, _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n
                 _V_a_r_i_a_b_l_e_s for the precedence of internationalization
                 variables used to determine the values of locale categories.)

       _L_C___A_L_L    If set to a non-empty string value, override the values of
                 all the other internationalization variables.

       _L_C___C_O_L_L_A_T_E
                 Determine the locale for the behavior of ranges, equivalence
                 classes, and multi-character collating elements within
                 regular expressions.

       _L_C___C_T_Y_P_E  Determine the locale for the interpretation of sequences of
                 bytes of text data as characters (for example, single-byte as
                 opposed to multi-byte characters in arguments and input
                 files) and the behavior of character classes within regular
                 expressions.

       _L_C___M_E_S_S_A_G_E_S
                 Determine the locale that should be used to affect the format
                 and contents of diagnostic messages written to standard
                 error.

       _N_L_S_P_A_T_H   Determine the location of message catalogs for the processing
                 of _L_C___M_E_S_S_A_G_E_S.

AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
       Default.

SSTTDDOOUUTT
       If the --ll option is in effect, the following shall be written for each
       file containing at least one selected input line:

           ""%%ss\\nn"",, <<_f_i_l_e>

       Otherwise, if more than one _f_i_l_e argument appears, and --qq is not
       specified, the _g_r_e_p utility shall prefix each output line by:

           ""%%ss::"",, <<_f_i_l_e>

       The remainder of each output line shall depend on the other options
       specified:

        *  If the --cc option is in effect, the remainder of each output line
           shall contain:

               ""%%dd\\nn"",, <<_c_o_u_n_t>

        *  Otherwise, if --cc is not in effect and the --nn option is in effect,
           the following shall be written to standard output:

               ""%%dd::"",, <<_l_i_n_e _n_u_m_b_e_r>

        *  Finally, the following shall be written to standard output:

               ""%%ss"",, <<_s_e_l_e_c_t_e_d_-_l_i_n_e _c_o_n_t_e_n_t_s>

SSTTDDEERRRR
       The standard error shall be used only for diagnostic messages.

OOUUTTPPUUTT FFIILLEESS
       None.

EEXXTTEENNDDEEDD DDEESSCCRRIIPPTTIIOONN
       None.

EEXXIITT SSTTAATTUUSS
       The following exit values shall be returned:

        0    One or more lines were selected.

        1    No lines were selected.

       >1    An error occurred.

CCOONNSSEEQQUUEENNCCEESS OOFF EERRRROORRSS
       If the --qq option is specified, the exit status shall be zero if an
       input line is selected, even if an error was detected. Otherwise,
       default actions shall be performed.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       Care should be taken when using characters in _p_a_t_t_e_r_n___l_i_s_t that may
       also be meaningful to the command interpreter. It is safest to enclose
       the entire _p_a_t_t_e_r_n___l_i_s_t argument in single-quotes:

           ''......''

       The --ee _p_a_t_t_e_r_n___l_i_s_t option has the same effect as the _p_a_t_t_e_r_n___l_i_s_t
       operand, but is useful when _p_a_t_t_e_r_n___l_i_s_t begins with the <hyphen>
       delimiter. It is also useful when it is more convenient to provide
       multiple patterns as separate arguments.

       Multiple --ee and --ff options are accepted and _g_r_e_p uses all of the
       patterns it is given while matching input text lines.  (Note that the
       order of evaluation is not specified. If an implementation finds a null
       string as a pattern, it is allowed to use that pattern first, matching
       every line, and effectively ignore any other patterns.)

       The --qq option provides a means of easily determining whether or not a
       pattern (or string) exists in a group of files. When searching several
       files, it provides a performance improvement (because it can quit as
       soon as it finds the first match) and requires less care by the user in
       choosing the set of files to supply as arguments (because it exits zero
       if it finds a match even if _g_r_e_p detected an access or read error on
       earlier _f_i_l_e operands).

EEXXAAMMPPLLEESS
        1. To find all uses of the word ""PPoossiixx"" (in any case) in file tteexxtt..mmmm
           and write with line numbers:

               ggrreepp --ii --nn ppoossiixx tteexxtt..mmmm

        2. To find all empty lines in the standard input:

               ggrreepp ^^$$

           or:

               ggrreepp --vv ..

        3. Both of the following commands print all lines containing strings
           ""aabbcc"" or ""ddeeff"" or both:

               ggrreepp --EE ''aabbcc||ddeeff''

               grep -F 'abc
               def'

        4. Both of the following commands print all lines matching exactly
           ""aabbcc"" or ""ddeeff"":

               ggrreepp --EE ''^^aabbcc$$||^^ddeeff$$''

               grep -F -x 'abc
               def'

RRAATTIIOONNAALLEE
       This _g_r_e_p has been enhanced in an upwards-compatible way to provide the
       exact functionality of the historical _e_g_r_e_p and _f_g_r_e_p commands as well.
       It was the clear intention of the standard developers to consolidate
       the three _g_r_e_ps into a single command.

       The old _e_g_r_e_p and _f_g_r_e_p commands are likely to be supported for many
       years to come as implementation extensions, allowing historical
       applications to operate unmodified.

       Historical implementations usually silently ignored all but one of
       multiply-specified --ee and --ff options, but were not consistent as to
       which specification was actually used.

       The --bb option was omitted from the OPTIONS section because block
       numbers are implementation-defined.

       The System V restriction on using -- to mean standard input was omitted.

       A definition of action taken when given a null BRE or ERE is specified.
       This is an error condition in some historical implementations.

       The --ll option previously indicated that its use was undefined when no
       files were explicitly named. This behavior was historical and placed an
       unnecessary restriction on future implementations. It has been removed.

       The historical BSD _g_r_e_p --ss option practice is easily duplicated by
       redirecting standard output to //ddeevv//nnuullll.  The --ss option required here
       is from System V.

       The --xx option, historically available only with _f_g_r_e_p, is available
       here for all of the non-obsolescent versions.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _s_e_d

       The Base Definitions volume of POSIX.1-2008, _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t
       _V_a_r_i_a_b_l_e_s, _C_h_a_p_t_e_r _9, _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x
       _G_u_i_d_e_l_i_n_e_s

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                              GREP(1)
