Grep, egrep and their corresponding regular expressions and usage
Grep: grep,egrep,fgrep, text search tool, fuzzy search for given text based on PATTERN. GREP works in greedy mode by default.
Grep:
Grep [OPTIONS] PATTERN [FILE...]
PATTERN: the filter condition consists of regular expression metacharacters and text characters that have no special meaning.
Regular expression metacharacters:
Will be interpreted as a special meaning by the regular expression engine. Regular expression engine for the pcre--perl language.
Basic regular expression: BRE
Extended regular expression: ERE
Grep only supports basic regular expressions by default
Egrep only supports extended regular expressions by default.
Fgrep does not turn on the regular expression engine by default
Text characters:
Those characters that have only one-sided meaning
Common options:
-I,-- ignore-case ignores the case of text characters
-v,-- invert-match match in reverse, and the final result is the row that PATTREN cannot match
-c,-- count counts all rows that match PATTERN
-o,-- only-matching turns off greedy mode and displays only what PATTERN can match
-Q,-- quiet,-- silent does not output any matching results
-- color [= WHEN],-- colour [= WHEN] displays the contents of the matching PATTREN in a special color
-E,-- extended-regexp extended regular expression grep-E is equivalent to egrep
-F,-- fixed-strings,-- fixed-regexp is equivalent to fgrep
-G,-- basic-regexp basic regular expression, egrep-G is equivalent to grep
-P,-- perl-regexp uses the PCRE engine
-A NUM,-- after-context=NUM displays the rows that match the PATTERN and the NUM lines that follow them
-B NUM-- before-context=NUM
PATTERN
Regular expression metacharacters:
Basic regular expression metacharacters:
GLOBBING- simplified version of regular expression: []? *
Character matching:
.: match any single character
[]: matches any single character in the specified range
[^]: matches any single character outside the specified range
All of the following character sets can be placed in [] to match a single character
[: lower:]
[: upper:]
[: alpha:]
[: digit:]
[: space:] Spac
[: alnum:]
[: punct:]
[: blank:]
[: xdigit:]: all hexadecimal numbers
Amurz: all lowercase letters
Amurz: all capital letters
0-9: all decimal numbers
Number of times matching: the number of times that a character before this class can appear
*: the character in front of it can appear any number of times (0, 1 or more times)
The character in front of it is optional (0 times or once)
\ +: the character preceding it appears at least once (1 or more times)
\ {m\}: the character before it must appear m times
\ {mdirection n\}: at least m times and at most n times (m)