• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

grep

grep

grep  
egrep  
fgrep Prints lines matching a pattern.
grep [options] <pattern> <file1> <file2>… grep [options] [-e <pattern> | -f <file>] <file1> <file2>
grep searches the list of files enumerated by <file1> <file2> …, or standard input if no file is specified or if - is specified. By default, the matching lines are printed.
Two additional variants of the program are available as egrep (same as grep -E) or fgrep (same as grep -F).
-A <num> Prints <num> lines of trailing context after matching lines.
—after-context=<num> Same as -A <num>.
-a Processes a binary file as if it were a text file. Equivalent to -binary-files=text option.
—text Same as -a.
-B <num> Prints <num> lines of leading context before matching lines.
—before-context=<num> Same as -B <num>.
-C <num> Prints <num> lines of output context. Default is 2.
-<num> Same as -C <num>.
—context[=<num>] Same as -C <num>.
-b Prints the byte offset within the input file before each line of output.
—byte-offset Same as -b.
—binary-files=<type> Assumes a file is of type <type> if the first few bytes of a file contain binary data.

Default <type> is binary, and grep normally outputs a one-line message indicating the file is binary, or nothing if there is no match.

If <type> is without-match, it is assumed that a binary file does not match. Equivalent to -I option.

If <type> is text, it processes the file as though it were a text file. Equivalent to -a option. Warning: Using this option could result in binary garbage being output to a terminal, some of which could be interpreted by the terminal as commands, resulting in unwanted side effects.
-I Assumes a binary file does not match. Equivalent to -binary-files=without-match option.
-c Prints a count of matching lines for each file. Combined with -v, counts nonmatching lines.
—count Same as -c.
-v Inverts matching to select non-matching lines.
—invert-match Same as -v.
-d <action> If input file is a directory, uses <action> to process it.

If <action> is read, grep reads directories as if they were normal files. This is the default.

If <action> is skip, it silently skips directories.

If <action> is recurse, it recursively reads files under the directory. Equivalent to -r.
—directories=<action> Same as -d <action>.
-r Recursively reads files under directories. Equivalent to -d recursive option.
—recursive Same as -r.
-f <file> Reads a list of patterns from <file>, which contains one pattern per line. An empty file has no patterns and matches nothing.
—file=<file> Same as -f <file>.
-e <pattern> Uses <pattern> as the pattern. Useful for protecting patterns beginning with -.
-regexp=<pattern> Same as -e <pattern>.
-G Interprets <pattern> as a basic regular expression. This is the default behavior.
—basic-regexp Same as above.
-E Interprets <pattern> as an extended regular expression. Equivalent to egrep.
-extended-regexp Same as -E.
-F Interprets <pattern> as a list of fixed strings, separated by newlines, any of which are to be matched. Equivalent to fgrep.
—fixed-strings Same as -F.
-H Prints the filename for each match.
—with-filename Same as -H.
-h Suppresses filenames on output when multiple files are searched.
—no-filename Same as -h.
—help Displays a brief help message.
-i Ignores case in <pattern> and input files.
—ignore-case Same as -i.
-L Prints a list of files that do not have matches. Stops scanning after the first match.
-l Prints a list of files that contain matches.
—mmap If possible, uses mmap(2) system call rather than the default read(2) system call. Sometimes -mmap results in better performance. However, it can cause unexpected behavior, such as core dumps, if the file shrinks while grep is reading it or if an I/O error occurs.
-n Output includes the line number where the match occurs.
—line-number Same as -n.
-q Quiet. Suppresses normal output. Scanning stops on the first match. Also see the -s and -no-messages options.
—quiet Same as -q.
—silent Same as -q.
-s Suppresses error messages about nonexistent or unreadable files.
—no-messages Same as -s.
-V Prints the version number of grep to standard error. Includes the version number in all bug reports.
—version Same as -V.
-w Selects only lines that have matches that form whole words.
—word-regexp Same as -w.
-x Selects only those matches that exactly match the whole line.
—line-regexp Same as -x.
-Z Outputs a zero byte (the ASCII NUL character) instead of the character that normally follows a filename. This option makes the output unambiguous, even for filenames containing unusual characters such as newlines.
—null Same as -Z.
-y Obsolete equivalent for -i.
-U Has no effect on platforms other than MS-DOS and MS Windows. On those platforms, treats files as binary files to affect how CR characters are handled.
—binary Same as -U.
-u Has no effect on platforms other than MS-DOS and MS Windows. On those platforms, reports Unix-style byte offsets; that is, with CR characters stripped off.
—unix-byte-offsets Same as -u.



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint