grep

grep - Command to match a specified pattern.

grep(1)                                                             grep(1)

NAME
     grep, egrep, fgrep - search a file for a pattern

SYNOPSIS

   Plain call with pattern
     grep [-E|-F] [-c|-l|-q] [-insvx] pattern [file ...]

   Call with (multiple) -e pattern
     grep [-E|-F] [-c|-l|-q] [-binsvx] -e pattern...  [-e pattern] ...
          [file ...]

   Call with -f file
     grep [-E|-F] [-c|-l|-q] [-insvx] [-f pattern_file] [file ...]

   Obsolescent:
     egrep [-cefilnsv] [expression] [file ...]

     fgrep [-cefilnsvx] [strings] [file ...]

DESCRIPTION
     The grep command searches the input text files (standard input
     default) for lines matching a pattern.  Normally, each line found is
     copied to the standard output.  grep supports the Basic Regular
     Expression syntax (see regexp(5)).  The -E option (egrep) supports
     Extended Regular Expression (ERE) syntax (see regexp(5)).  The -F
     option (fgrep) searches for fixed strings using the fast Boyer-Moore
     string searching algorithm.  The -E and -F options treat newlines
     embedded in the pattern as alternation characters.  A null expression
     or string matches every line.

     The forms egrep and fgrep are maintained for backward compatibility.
     The use of the -E and -F options is recommended for portability.

   Options
          -E                  Extended regular expressions.  Each pattern
                              specified is a sequence of one or more EREs.
                              The EREs can be separated by newline
                              characters or given in separate -e expression
                              options.  A pattern matches an input line if
                              any ERE in the sequence matches the contents
                              of the input line without its trailing
                              newline character.  The same functionality is
                              obtained by using egrep.

          -F                  Fixed strings.  Each pattern specified is a
                              sequence of one or more strings.  Strings can
                              be separated by newline characters or given
                              in separate -e expression options.  A pattern
                              matches an input line if the line contains
                              any of the strings in the sequence.  The same
                              functionality is obtained by using fgrep.

          -b                  Each line is preceded by the block number on
                              which it was found.  This is useful in
                              locating disk block numbers by context.
                              Block numbers are calculated by dividing by
                              512 the number of bytes that have been read
                              from the file and rounding down the result.


          -c                  Only a count of matching lines is printed.

          -e expression       Same as a simple expression argument, but
                              useful when the expression begins with a
                              hyphen (-).  Multiple -e options can be used
                              to specify multiple patterns; an input line
                              is selected if it matches any of the
                              specified patterns.

          -f pattern_file     The regular expression (grep and grep -E) or
                              strings list (grep -F) is taken from the
                              pattern_file.

          -i                  Ignore uppercase/lowercase distinctions
                              during comparisons.

          -l                  Only the names of files with matching lines
                              are listed (once), separated by newlines.  If
                              standard input is searched, a path name of -
                              is listed.

          -n                  Each line is preceded by its relative line
                              number in the file starting at 1.  The line
                              number is reset for each file searched.  This
                              option is ignored if -c, -b, -l, or -q is
                              specified.

          -q                  (Quiet) Do not write anything to the standard
                              output, regardless of matching lines.  Exit
                              with zero status upon finding the first
                              matching line.  Overrides any options that
                              would produce output.

          -s                  Error messages produced for nonexistent or
                              unreadable files are suppressed.

          -v                  All lines but those matching are printed.

          -x                  (eXact) Matches are recognized only when the
                              entire input line matches the fixed string or
                              regular expression.

     In all cases in which output is generated, the file name is output if
     there is more than one input file.  Care should be taken when using
     the characters $, *, [, ^, |, (, ), and  in expression, because they
     are also meaningful to the shell.  It is safest to enclose the entire
     expression argument in single quotes ('...').

EXTERNAL INFLUENCES
   Environment Variables
     LANG determines the locale to use for the locale categories when both
     LC_ALL and the corresponding environment variable (beginning with LC_)
     do not specify a locale.  If LANG is not specified or is set to the
     empty string, a default of C (see lang(5)) is used.

     LC_ALL determines the locale to use to override any values for locale
     categories specified by the settings of LANG or any environment
     variables beginning with LC_.

     LC_COLLATE determines the collating sequence used in evaluating
     regular expressions.

     LC_CTYPE determines the interpretation of text as single byte and/or
     multi-byte characters, the classification of characters as letters,
     the case information for the -i option, and the characters matched by
     character class expressions in regular expressions.

     LC_MESSAGES determines the language in which messages are displayed.

     If any internationalization variable contains an invalid setting, the
     commands behave as if all internationalization variables are set to C.
     See environ(5).

   International Code Set Support
     Single-byte and multi-byte character code sets are supported.

RETURN VALUE
     Upon completion, grep returns one of the following values:

          0    One or more matches found.
          1    No match found.
          2    Syntax error or inaccessible file (even if matches were
               found).

EXAMPLES
     In the Bourne shell (sh(1)) the following example searches two files,
     finding all lines containing occurrences of any of four strings:

          grep -F 'if
          then
          else
          fi' file1 file2

     Note that the single quotes are necessary to tell grep -F when the
     strings have ended and the file names have begun.

     For the C shell (see csh(1)) the following command can be used:

          grep -F 'if then else fi' file1 file2

     To search a file named address containing the following entries:

          Ken   112 Warring St.  Apt. A
          Judy  387 Bowditch  Apt. 12
          Ann   429 Sixth St.

     the command:

          grep Judy address

     prints:

          Judy  387 Bowditch  Apt. 12

     To search a file for lines that contain either a Dec or Nov, use
     either of the following commands:

          grep -E '[Dd]ec|[Nn]ov' file

          egrep -i 'dec|nov' file

     Search all files in the current directory for the string xyz:

          grep xyz *

     Search all files in the current directory subtree for the string xyz,
     and ensure that no error occurs due to file name expansion exceeding
     system argument list limits:

          find . -type f -print |xargs grep xyz

     The previous example does not print the name of files where string xyz
     appears.  To force grep to print file names, add a second argument to
     the grep command portion of the command line:

          find . -type f -print |xargs grep xyz /dev/null

     In this form, the first file name is that produced by find, and the
     second file name is the null file.

WARNINGS
     (XPG4 only.) If the -q option is specified, the exit status will be
     zero if an input line is selected, even if an error was detected.
     Otherwise, default actions will be performed.

SEE ALSO
     sed(1), sh(1), regcomp(3C), environ(5), lang(5), regexp(5).

STANDARDS CONFORMANCE
     grep: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2

     egrep: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2

     fgrep: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.157.39