Command Prompt for Windows




Command GREP

Function:

Display lines matching a pattern.

Download:

Syntax:

GREP [/[[AB] ]num] [/[CEFGVchilnqsvwx]] [/[ef]] expr [files...]

There are three major variants of grep, controlled by the following options :-

/GInterpret pattern as a basic regular expression. This is the default.
/EInterpret pattern as an extended regular expression.
/FInterpret pattern as a list of fixed strings, separated by newlines, any of which is to be matched.

All variants of grep understand the following options :-

/numMatches will be displayed with num lines of leading and trailing context. However, grep will never display any given line more than once.
/A numDisplay num lines of trailing context after matching lines.
/B numDisplay num lines of leading context before matching lines.
/CEquivalent to -2.
/VDisplay the version number of grep.
/bDisplay the byte offset within the input file before each line of output.
/cSuppress normal output; instead display a count of matching lines for each input file. With the -v option, count non-matching lines.
/eUse pattern as the pattern; useful to protect patterns beginning with -.
/f fileObtain the pattern from file.
/hSuppress the prefixing of filenames on output when multiple files are searched.
/iIgnore case distinctions in both the pattern and the input files.
/LSuppress normal output; instead display the name of each input file from which no output would normally have been displayed.
/lSuppress normal output; instead display the name of each input file from which output would normally have been displayed.
/nPrefix each line of output with the line number within its input file.
/qQuiet; suppress normal output.
/sSuppress error messages about nonexistent or unreadable files.
/vInvert the sense of matching, to select non-matching lines.
/wSelect only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.
/xSelect only those matches that exactly match the whole line.

Note:

Grep searches the named input files (or standard input if no files are named, or the file name - is given) for lines containing a match to the given pattern. By default, grep displays the matching lines.

GREP is an ANSI only command and does not support UNICODE.

Also see command FIND and Regular Expressions.