One, grep global search regular expression, and print out the row
Function: Text Search tool, according to user-specified "mode (filter)" to match the target text line by row to check; print matching lines;
Pattern: The filter condition written by metacharacters and text characters of regular expressions;
The regular expression engine;
grep [OPTIONS] PATTERN [FILE ...]
grep [OPTIONS] [-E PATTERN |-f file] [FILE ...]
OPTIONS:
--color=auto: Color The matching text to highlight;
-i:ignorecase, ignoring the case of characters;
-O: Displays only the string that matches to itself;
-V,--invert-match: Displays the rows that cannot be matched by the pattern;
-E: Supports the use of extended regular expression metacharacters;
-Q,--quiet,--silent: Silent mode, that is, do not output any information;
-A #:after, after # line
-B #:before, front # line
-c #:context, front and back # lines
Basic regular Expression meta-characters:
Character Matching:
. : matches any single character;
[]: matches any single character within the specified range;
[^]: matches any single character outside the specified range;
[:d Igit:], [: Lower:], [: Upper:], [: Alpha:], [: Alnum:], [:p UNCT:], [: Space:]
Number of matches: used to limit the number of occurrences of the preceding character after the character to specify the number of occurrences, and the default work is in greedy mode;
*: Matches its preceding character any time, 0, 1, multiple times;
. *: Matches any character of any length
\?: matches the preceding character 0 or 1 times, that is, the preceding character is optional;
\+: Matches the preceding character 1 or more times, i.e. the character of its face must appear at least 1 times;
\{m\}: Matches the preceding character m times;
\{m,n\}: Matches its preceding character at least m times, up to n times;
\{0,n\}: Up to n times
\{m,\}: At least m times
Location anchoring:
^: Anchor at the beginning of the line, for the leftmost mode;
$: End of line anchoring; for the rightmost side of the pattern;
^pattern$: Used for PATTERN to match whole line;
^$: blank line;
^[[:space:]]*$: A blank line or a line containing white space characters;
Word: A continuous character (string) consisting of a non-special character is called a word;
\< or \b: The first anchor of the word, used for the left side of the word pattern;
\> or \b: The ending anchor for the right side of the word pattern;
\<pattern\>: matches complete words;
Second, Egrep an extended regular expression implementation is similar to the grep text filtering feature; Grep-e
Egrep [OPTIONS] PATTERN [FILE ...]
Options:
-I,-O,-V,-Q,-A,-B,-C
-G: Support for basic regular expressions
Extend the metacharacters of regular expressions:
Character Matching:
.: Any single character
[]: Any single character within the specified range
[^]: Any single character outside the specified range
Number of matches:
*: Any time, 0,1 or multiple times;
?: 0 or 1 times, before the characters are optional;
+: Its preceding character at least 1 times;
{m}: its preceding character m times;
{M,n}: At least m times, up to n times;
{0,n}
{m,}
Position anchoring
^: Anchor at the beginning of the line;
$: End of line anchoring;
\< \b: The first anchor of the word;
\> \b: the final anchor;
Grouping and referencing:
(): grouping; the character that the pattern in parentheses matches to is recorded hermetical the internal variables of the expression engine;
Back reference: \1, \2, ...
Or:
A|b:a or B;
C|cat:c or Cat
(c| C) At:cat or cat
This article from "Everything from scratch, do not forget beginner's mind." "Blog, be sure to keep this provenance http://liaodijin.blog.51cto.com/10988244/1730878
grep, Egrep