GREP
GREP
Section: User Commands (1)
Name
GREP, EGREP, FGREP - Print the line that matches the given mode
Total stemsis
GREP [options] pattern [file...]
Grep [options] [-e pattern | -f file] [file...]
Description Description
GREP Search for file input (or standard input, if you do not specify file name, or given the file name), find the model with a given mode
Pattern matches the content of the content. By default, GREP will print out rows containing matching content.
Alternatively, two variant procedures EGREP and FGREP can also be used. EGREP is the same as GREP -E. FGREP is the same as GREP -F.
Option options
-A Num, - -AFTER-Context = Num
Print the following NUM line after the matching line. The print content is in the adjacent matching group.
-a, - -text
Take a binary as a text file to handle; it is equivalent to--binary-files = text option.
-B Num, - -before-context = NUM
Print the above NUM line before the matching row. The print content is in the adjacent matching group.
-C num, - -Context = NUM
Print each NUM line before and after the context of the matching row. The print content is in the adjacent matching group.
-b, - -byte-offset
Print the byte offset of the current row in the input file in front of each line output.
- -binary-files = TYPE
If a file starting a few bytes indicate that the file contains binary data, then the file is type TYPE type. By default, Type is binary, and GREP
Generally output a line of messages say a binary match, or if there is no message output if there is no match. If the type Type is without-match, then
What GREP assumes that the binary does not match; doing this is equivalent to the -i option. If the type type is text, then GREP regards a binarily as a text file.
Treatment; it is equivalent to -A option. Warning: grep - -binary-files = text may output binary useless content. If the output device is a terminal, and the terminal
Drivers to bring some of these output as a command, may bring bad side effects.
- -COLOUR [= when], - -color [= when]
Tagged around the marker specified in the GREP_COLOR environment variable around the match. When can be `never ',` always', or `auto'.
-c, - -count
It is forbidden to output; as an alternative, print a matching line for each input file. If you use the -v, - -invert-match option (see below), will not
The total number of matches.
-D action, - -Devices = action
If the input file is a device, FIFO, or socket, use action action to handle it. By default, action action is Read, meaning
The device will be read as normal files. If the action action is SKIP, it will not be processed and directly skipped.
-d action, - -directories = action
If the input file is a directory, use action action to process it. By default, action action is Read, meaning that the directory will be read as normal files. If the action action is SKIP, you will not be processed directly to skip the directory. If the action action is Recurse, GREP will recursively read all files in each directory.
Do this and -r option equivalent.
-E, - -extended-regexp
Interpretation pattern Pattern as an extended regular expression (see below).
-e pattern, - -Regexp = Pattern
Use mode pattern as a mode; useful when protected.
-F, - -fixed-strings
The mode Pattern is treated as a list of fixed strings, separated by NEWLINES, as long as one of them can be matched.
-P, - -perl-regexp
Explain the mode Pattern as a Perl regular expression.
-f file, - -file = file
Get the mode from the file file, one per line. Empty files contain 0 modes, so do not match anything.
-G, - -basic-regexp
Explanation pattern as a basic regular expression (see below). It's the default value.
-H, - -with-filename
Print the file name for each match.
-H, - -NO-filename
When searching for multiple files, it is forbidden to add a file name prefix in front of the output.
-Help
Output a short help information.
-I
Handle a binary file, but think it does not contain the matching content. This is the equivalent of this and - -binary-files = without-match option.
-i, - -ignore-case
Ignore the model pattern and the sinks in the input file.
-L, - -files-without-match
It is forbidden to output; an alternative, printed that each name of the input file that does not produce the output in general. The scan for each file is encountered when you encounter the first match.
Will stop.
-l, - -files-with-matches
It is forbidden to output; an alternative, print each name of the input file that will generate output in general. The scan for each file will encounter the first match.
stop.
-m Num, - -max-count = Num
After finding the NUM matched row, no longer read this file. If the input is a standard input from a normal file, NUM matches have been output, GREP
Ensure that the standard input is positioned in the last matching line of exit, whether or not to output the following row to output. This allows a caller to recover search.
When GREP stops after NUM matches, it outputs any of the following rows. When using the -c or--count option, GREP does not output a ratio
Num more rows. When the -v or--invert-match option is specified, GREP will stop after the NUM does not match.
-Mmap
If possible, use the MMAP (2) system call to read the input instead of the default READ (2) system call. In some cases, - -mmap provides better performance.
However, if a input file changes in the size of GREP, or if an I / O error has occurred, - -mmap may result in unknown behavior (including
Core dumps.
-n, - -Line-Number
In front of the output of each line, add its line number in its file.
-o, - -only-matching
Only the part of the matching row is displayed.
- -Label = Label will actually be deemed from the standard input to the input file label. This is very useful for tools such as ZGREP, such as gzip -cd foo.gz | grep
--Label = foo Something
-Line-Buffering
Using row buffers, IT can be a performance penetity.
-q, - -quiet, - -silent
be quiet. No things are written to the standard output. If you find any matching content, you immediately exit as status value 0, even if an error is detected. See -S or
- -no-messages option.
-R, -r, - -recursive
Recursively read all files in each directory. Do this and the -d recurse option is equivalent.
- -include = pattern
Recursively recursively searching in the directory only when searching for files matching Pattern.
- -EXCLUDE = Pattern
Recursively search in the directory, but skip the file that matches Pattern.
-S, - -NO-Messages
It is forbidden to output an error message about the file does not exist or unreadable. Note for portability: Unlike GNU GREP, traditional GREP does not comply with POSIX.2 norms, because
Lack of a -q option for traditional GREP, and its -s option is similar to the -Q option behavior of GNU GREP. The shell script that needs to be ported to the traditional GREP should
Avoid using the -Q and -S option, and the output should be redirected to / dev / null.
-U, - -binary
Demonstrate files as binary. By default, in the MS-DOS and MS-Windows systems, GREP determines its file type by reading 32KB content from the file.
. If the grep judgment file is a text file, it removes the CR character in the original file content (so that the regular expressions containing ^ and $ can work). Specify
-U will not perform these work, and all files remain unchanged and passed to the matching mechanism. If the file is a text file that is wrapped in CR / LF, this will result in one
Some regular expressions failed. This option is invalid in the system other than MS-DOS and MS-Windows.
-u, - -unix-byte-offsets
Report a Unix style byte offset. This switch allows the GREP report byte offset, treats the file as a text file of UNIX style, that is, say CR characters
Remove. This will produce the same result as the result of GREP on a UNIX host. This option is invalid unless the -b option is used at the same time. This option is in MS-DOS
Invalidation in systems other than MS-Windows.
-V, - -version
Output the version number of the GREP to the standard error. The version number should be included in all BUG reports (see below).
-v, - -invert-match
Changing the meaning of the match, only selects the mismatched row.
-w, - -word-regexp
Just select a row that contains a match that can make a complete word. The judgment method is that the matched sub-string must be the beginning of a row, or after a character that cannot be a word.
Similar to this, it must be the end of a row, or before a character that cannot be a word. The composition of the word is a letter, a number, and an underscore.
-X, - -Line-regexp
Just choose to match the full line of matching.
-y
-i synonym, abandonment is not available.
-Z, - -null
Outputs a full zone (NUL character in the ASCII code) instead of the character to output the file name after the file name. For example, GREP -LZ outputs after each file name
A whole byte rather than ordinary new line characters. This option makes the output clearly, even if the file names include special characters such as new line characters. This option can be used with command Find -Print0, Perl -0, sort -z, and xargs -0 to process any file name, even those file names that contain new lines. GREP
GREP
Section: User Commands (1)
Name
GREP, EGREP, FGREP - Print the line that matches the given mode
Total stemsis
GREP [options] pattern [file...]
Grep [options] [-e pattern | -f file] [file...]
Description Description
GREP Search for file input (or standard input, if you do not specify file name, or given the file name), find the model with a given mode
Pattern matches the content of the content. By default, GREP will print out rows containing matching content.
Alternatively, two variant procedures EGREP and FGREP can also be used. EGREP is the same as GREP -E. FGREP is the same as GREP -F.
Option options
-A Num, - -AFTER-Context = Num
Print the following NUM line after the matching line. The print content is in the adjacent matching group.
-a, - -text
Take a binary as a text file to handle; it is equivalent to--binary-files = text option.
-B Num, - -before-context = NUM
Print the above NUM line before the matching row. The print content is in the adjacent matching group.
-C num, - -Context = NUM
Print each NUM line before and after the context of the matching row. The print content is in the adjacent matching group.
-b, - -byte-offset
Print the byte offset of the current row in the input file in front of each line output.
- -binary-files = TYPE
If a file starting a few bytes indicate that the file contains binary data, then the file is type TYPE type. By default, Type is binary, and GREP
Generally output a line of messages say a binary match, or if there is no message output if there is no match. If the type Type is without-match, then
What GREP assumes that the binary does not match; doing this is equivalent to the -i option. If the type type is text, then GREP regards a binarily as a text file.
Treatment; it is equivalent to -A option. Warning: grep - -binary-files = text may output binary useless content. If the output device is a terminal, and the terminal
Drivers to bring some of these output as a command, may bring bad side effects.
- -COLOUR [= when], - -color [= when]
Tagged around the marker specified in the GREP_COLOR environment variable around the match. When can be `never ',` always', or `auto'.
-c, - -count
It is forbidden to output; as an alternative, print a matching line for each input file. If you use the -v, - -invert-match option (see below), will not
The total number of matches.
-D action, - -Devices = action
If the input file is a device, FIFO, or socket, use action action to handle it. By default, action action is Read, meaning that the device will be read as normal files. If the action action is SKIP, it will not be processed and directly skipped.
-d action, - -directories = action
If the input file is a directory, use action action to process it. By default, action action is Read, meaning that the directory will be read as normal files.
If the action action is SKIP, you will not be processed directly to skip the directory. If the action action is Recurse, GREP will recursively read all files in each directory.
Do this and -r option equivalent.
-E, - -extended-regexp
Interpretation pattern Pattern as an extended regular expression (see below).
-e pattern, - -Regexp = Pattern
Use mode pattern as a mode; useful when protected.
-F, - -fixed-strings
The mode Pattern is treated as a list of fixed strings, separated by NEWLINES, as long as one of them can be matched.
-P, - -perl-regexp
Explain the mode Pattern as a Perl regular expression.
-f file, - -file = file
Get the mode from the file file, one per line. Empty files contain 0 modes, so do not match anything.
-G, - -basic-regexp
Explanation pattern as a basic regular expression (see below). It's the default value.
-H, - -with-filename
Print the file name for each match.
-H, - -NO-filename
When searching for multiple files, it is forbidden to add a file name prefix in front of the output.
-Help
Output a short help information.
-I
Handle a binary file, but think it does not contain the matching content. This is the equivalent of this and - -binary-files = without-match option.
-i, - -ignore-case
Ignore the model pattern and the sinks in the input file.
-L, - -files-without-match
It is forbidden to output; an alternative, printed that each name of the input file that does not produce the output in general. The scan for each file is encountered when you encounter the first match.
Will stop.
-l, - -files-with-matches
It is forbidden to output; an alternative, print each name of the input file that will generate output in general. The scan for each file will encounter the first match.
stop.
-m Num, - -max-count = Num
After finding the NUM matched row, no longer read this file. If the input is a standard input from a normal file, NUM matches have been output, GREP
Ensure that the standard input is positioned in the last matching line of exit, whether or not to output the following row to output. This allows a caller to recover search.
When GREP stops after NUM matches, it outputs any of the following rows. When using the -c or--count option, GREP does not output a ratio
Num more rows. When the -v or--invert-match option is specified, GREP will stop after the NUM does not match.
-Mmap
If possible, use the MMAP (2) system call to read the input instead of the default READ (2) system call. In some cases, - -mmap provides better performance.
However, if a input file changes during the operation when the GREP is operating, or if an I / O error has occurred, - -mmap may result in unknown behavior (including Core Dumps).
-n, - -Line-Number
In front of the output of each line, add its line number in its file.
-o, - -only-matching
Only the part of the matching row is displayed.
- -Label = label
The input that is actually from standard input is considered to be from input file label. This is very useful for tools such as ZGREP, such as gzip -cd foo.gz | grep
--Label = foo Something
-Line-Buffering
Using row buffers, IT can be a performance penetity.
-q, - -quiet, - -silent
be quiet. No things are written to the standard output. If you find any matching content, you immediately exit as status value 0, even if an error is detected. See -S or
- -no-messages option.
-R, -r, - -recursive
Recursively read all files in each directory. Do this and the -d recurse option is equivalent.
- -include = pattern
Recursively recursively searching in the directory only when searching for files matching Pattern.
- -EXCLUDE = Pattern
Recursively search in the directory, but skip the file that matches Pattern.
-S, - -NO-Messages
It is forbidden to output an error message about the file does not exist or unreadable. Note for portability: Unlike GNU GREP, traditional GREP does not comply with POSIX.2 norms, because
Lack of a -q option for traditional GREP, and its -s option is similar to the -Q option behavior of GNU GREP. The shell script that needs to be ported to the traditional GREP should
Avoid using the -Q and -S option, and the output should be redirected to / dev / null.
-U, - -binary
Demonstrate files as binary. By default, in the MS-DOS and MS-Windows systems, GREP determines its file type by reading 32KB content from the file.
. If the grep judgment file is a text file, it removes the CR character in the original file content (so that the regular expressions containing ^ and $ can work). Specify
-U will not perform these work, and all files remain unchanged and passed to the matching mechanism. If the file is a text file that is wrapped in CR / LF, this will result in one
Some regular expressions failed. This option is invalid in the system other than MS-DOS and MS-Windows.
-u, - -unix-byte-offsets
Report a Unix style byte offset. This switch allows the GREP report byte offset, treats the file as a text file of UNIX style, that is, say CR characters
Remove. This will produce the same result as the result of GREP on a UNIX host. This option is invalid unless the -b option is used at the same time. This option is in MS-DOS
Invalidation in systems other than MS-Windows.
-V, - -version
Output the version number of the GREP to the standard error. The version number should be included in all BUG reports (see below).
-v, - -invert-match
Changing the meaning of the match, only selects the mismatched row.
-w, - -word-regexp
Just select a row that contains a match that can make a complete word. The judgment method is that the matched sub-string must be the beginning of a row, or after a character that cannot be a word.
Similar to this, it must be the end of a row, or before a character that cannot be a word. The composition of the word is a letter, a number, and an underscore.
-x, - -line-regexp only chooses a match that matches the full line.
-y
-i synonym, abandonment is not available.
-Z, - -null
Outputs a full zone (NUL character in the ASCII code) instead of the character to output the file name after the file name. For example, GREP -LZ outputs after each file name
A whole byte rather than ordinary new line characters. This option makes the output clearly, even if the file names include special characters such as new line characters. This option can be with command
Find -Print0, Perl -0, sort -z, and xargs -0 are used together to handle any file name, even those file names that contain new lines.
Regular expression Regular Expressions
A regular expression is a pattern describing a string set. Regular expressions are similar to arithmetic expressions, using a variety of operators to make smaller expressions
That is connected together.
GREP understands two different versions of regular expression syntax: Basic and Extended. In GNU GREP, the functions that the two syntax can be implemented is not different. In its
In his implementation, the basic (BASIC) regular expression is weak. The following description is suitable for extended regular expressions, which is with basic regular expressions
The difference will be a summary in the end.
The basic structural block is a regular expression that matches a single character. Most characters, including all letters and numbers, is a regular expression that matches their own. Any special meaning
Met characters can be referenced by a backslash. (May BE quoted by preceding it with a backslash.)
Brackets (Bracket) is a character sequence, placed in [and]. It matches any of the characters in the sequence; if the first character in the sequence is a destruction
(CARET) ^ Then it matches any of the characters that are not in the sequence. For example, regular expression [0123456789] matches any number.
Among the square brackets, a range expression (RANGE) consists of two characters, and the intermediate is separated by a hyphen. It matches between these two characters
Any character uses localized sequence sequences and character sets. (That Sorts Between the Two Characters, Inclusive, Using The Locale's
Collating Sequence and Character Set.) For example, in the default C Locale, [A-D] is equivalent to [ABCD] equivalent. Typically, many local will
Sort in the dictionary, in these locale, [A-D] is not equivalent to [ABCD] equivalent; for example, it may be equivalent to [abbccdd] equivalent. To get the interpretation of traditional counterpart bracket expressions
You can set the environment variable LC_all value to use Locale C.
Finally, there are some predefined character classes in square brackets, as shown below. Their names are self-explanatory, they are [: alnum:] (letters and numbers),
[: alpha:] (letters), [: cntrl:] (), [: graph:] (), [: Lower:] (lowercase letters), [: print:] Printable characters), [: punct:] (),
[: Space:] (space), [: Upper:] (uppercase letters), and [: xdigit:]. For example, [[: alnum:] means [0-9A-ZA-Z], but the latter representation is dependent on
Locale C and ASCII character encoding, and the former one is independent of Locale and character set. (Note that square brackets in these characters class are also part of the symbol name, must
It is included in square brackets used for the sequence. )
Most of the metades will lose their special meaning when they are in the sequence. In order to contain a literal (Literal), it is necessary to place it in the first place. Similarly, in order to include a literal (Literal), it is necessary to place it in other locations other than the sequence. Finally, in order to include a literal meaning (Literal)
-, need to put it in the sequence.
A PERIOD. Match any of the characters. Symbol / W is synonymous with [[: alnum:]], / w is synonymous with [^ [: alnum]].
The DRET (CARET) ^ and Dollar Mark (DOLLAR) $ is a metamorphism that matches the first and tail of the tail. Symbols /
Email character of the empty string of the ministry and tail. Symbol / B Matches the empty string of the word edge (Edge), the symbol / b matches the empty string string not in the edge of one word.
One regular expression can follow one of multiple repetitive operators.
?
Previous items are optional, up to once.
*
Previous items can match zero or multiple times.
Previous items can match once or more.
{n}
The previous item will match n times.
{n,}
Previous items can match n or more times.
{n, m}
Previous items will match at least n words, but will not exceed M times.
Two regular expressions can be connected together; the resulting regular expressions can match any strings connected by two sub-representings that match the sub-expression prior to the connection.
Two regular expressions can be combined with a infix operator | The resulting regular expression can match any string of any sub-expression before the combination.
The priority of the repeat operator is higher than that of the connection, which is higher than the selected priority. A complete child expression can be enclosed in parentheses (Preentheses) to surpass these priorities
Level rules. (To Override these Precedence Rules.)
In reverse reference / n, n is a number, matching the regular expression, which is hosted by the sub-expression that has a child expression in the nth parentheses.
In the basic regular expression, metamodes?, , {, |, (, And) lose their special meaning; as an alternative, use the backslash version /?,
/ , / {, / |, / (, And).
Traditional EGREP does not support metammatics {, and some EGREP implementations are replaced by support / {, so that portable scripts should avoid using {in EGREP {
Mode, [{] should be used to match a literal meaning {.
GNU EGREP By assume that if {is in an invalid interval specification, it is not a special character to support traditional usage. E.g
The shell command EGREP '{1' will search for this two-character string {1 instead of reporting a syntax error in the regular expression. POSIX.2 allows this behavior, will
It is considered an extension, but portable scripts should avoid using it.
Environmental Variable Environment Variables
GREP's behavior is affected by the following environment variables.
A Locale LC_FOO is determined by using the order of LC_all, lc_foo, lang, checking the value of these three environment variables. The first variable is set
Set Locale. For example, if lc_all is not set, but lc_messages are set to Pt_br, then Brazilian Portuguese will
Used as the value of LC_MESSAGES LOCALE. If you do not set any of these environment variables, or not install the set locale directory, or if GREP does not compile national and language support (National Language Support (NLS), Locale C will be used by default.
Grep_options
This variable specifies the default option before all explicitly specified options will be placed. For example, if grep_options is' - -binary-files = without-match
- -directories = skip ', GREP will be specified before any explicit specified options - -binary-files = without-match and
- -directories = SKIP option works. The option is separated by blank (Whitespace). A backslash enables the next character escape
(escape), so you can use an option to contain a blank or backslash.
GREP_COLOR
Specifies the tags used to highlight.
LC_all, lc_collate, lang
These variables specify that local lc_collate determines the sequence sequence when explaining the range expressions similar to [A-Z].
LC_all, LC_CTYPE, LANG
These options specify that locale lc_cType, determines the type of characters, for example, which characters are blank (Whitespace).
Lc_all, lc_messages, lang
These options specify local lc_messages to determine the language used by GREP messages. The default Locale C uses American English messages.
POSIXLY_CORRECT
If set, GREP will operate like POSIX.2 requirements; otherwise, GREP will operate like other GNU programs. POSIX.2 requires the file name
Options must be considered a file name; By default, these options are swapped to the front of the operand list, which is treated as an option. At the same time, POSIX.2 requires unrecognizable options
In the diagnostic message, it is expressed as Illegal, but since they don't really make the law, they are represented by the Diagnose message by default.
Posixly_correct also disables the _n_gnu_nonoption_argv_flags_ of the following description.
_N_gnu_nonoption_argv_flags_
(He is the process ID of the Grep's digital form.) If the value of the value of this environment variable is 1, then the GREP's i-th operands are not treated as a choice
Item, even if it looks like it. Shell can set this variable in the environment of each command it run, specify which operand is the result of file name wildcard expansion, so no
It should be considered as an option. This behavior is only valid when using the GNU C library, and only when POSIXLY_CORRECT is not set.
Diagnosis Diagnostics
Generally, if the selected row is found, the status value is 0 when exiting, otherwise 1. But if an error occurs, the status value is 2 when exiting, unless -q or -quiet or
- -silent option and find the selected row.
Bugs
The email address of the bug report is bug-gnu-Utils@gnu.org. Be sure to have a grep in Subject:
Excessive number of repetitions in {n, m} structure can cause grep to use a large amount of memory. In addition, some excessive regular expressions require an exponential time and space, which may cause GREP to exhaust all memory.
Backreferences (BACKERENCES) is very slow and may require an exponential time.
[Chinese version of the maintenance person]
Yuan Yi
[Chinese version latest update]
2003.11.03
"China Linux Forum MAN Handbook Translation Plan":
http://cmpp.linuxforum.net