Grep,egrep,fgrep:print lines matching a pattern
1.grep:
grep [options] PATTERN FILE ...
Pattern is made up of meta characters and ordinary characters
-I:--ignore-case, ignoring case
-O:--only-matching, displays only the characters that are matched, and two is not the whole line
-N:--line-number, outputs the line number of the matched row
-V:--invert-match, showing all rows except matching rows
-e:--extended-regexp, Egrep
-F:--fixed-strings, Fgrep
-P:--per-regexp
-A num:--after-context, which displays NUM lines after matching lines
-B Num:--before-context, display matching line strong NUM line
-C num:--context, displays the front and rear NUM lines of the matching line
Metacharacters
Match characters:
. : Matches any single character
[],[^]: matches the specified single character
[0-9], [[:d Igit:]]: matches a single number
[[: Alpha:]]: Matches a single large, lowercase letter
[[: Lower:]]: matches a single lowercase letter
[[: Upper:]]: Matches a single uppercase letter
[[: Alnum:]]: Matches a single number or letter
[[: Bank:]]: Matches a single white space character
[[:p UNCT:]]: Match punctuation
[[: Contrl:]]: match when control character
[[: Xdigit:]]: Matches a single 16 binary number
Number of matches: used to specify the number of occurrences of the preceding character
*: Any number of times, including 0
\+: At least once
\? : 0 or 1 times, the preceding characters can have, can be no
\{m\}, \{0,n\}, \{m,n\}, \{m,\}: Refers to M times, up to n times, m-n times, minimum m times
. *: Any length, any character
Location anchoring:
^: Anchor at the beginning of the line, mode left
$: End of line anchoring, mode right
\<: First anchor, Word pattern left, Word refers to a string of numbers and letters
\>: Ending anchor, Word right
^pattern$, matches the entire line only the specified pattern
^$: Blank Line
^[[:blank:]]$: No visible characters for entire line
\<word\>: Match Whole word
Group
\ (\) Enclose any character in parentheses to make a whole match.
Back reference: Apply the contents of the preceding grouping brackets, not the schema itself, \1,\2 ...
\ (th\). *\1: Matches what the first parenthesis matches
2. Egrep: Equivalent to GREP-E
egrep [options] PATTERN FILE ...
Pattern is made up of meta characters and ordinary characters
-I:--ignore-case, ignoring case
-O:--only-matching, displays only the characters that are matched, and two is not the whole line
-N:--line-number, outputs the line number of the matched row
-V:--invert-match, showing all rows except matching rows
-A num:--after-context, which displays NUM lines after matching lines
-B Num:--before-context, display matching line strong NUM line
-C num:--context, displays the front and rear NUM lines of the matching line
Pattern is made up of meta characters and ordinary characters
Metacharacters
Match characters:
. : Matches any single character
[],[^]: matches the specified single character
[0-9], [[:d Igit:]]: matches a single number
[[: Alpha:]]: Matches a single large, lowercase letter
[[: Lower:]]: matches a single lowercase letter
[[: Upper:]]: Matches a single uppercase letter
[[: Alnum:]]: Matches a single number or letter
[[: Bank:]]: Matches a single white space character
[[:p UNCT:]]: Match punctuation
[[: Contrl:]]: match when control character
[[: Xdigit:]]: Matches a single 16 binary number
Number of matches: used to specify the number of occurrences of the preceding character
*: Any number of times, including 0
+: At least once
? : 0 or 1 times, the preceding characters can have, can be no
{m}, {0,n}, {m,n}, {m,}: Refers to M times, up to n times, m-n times, minimum m times
. *: Any length, any character
Location anchoring:
^: Anchor at the beginning of the line, mode left
$: End of line anchoring, mode right
\<: First anchor, Word pattern left, Word refers to a string of numbers and letters
\>: Ending anchor, Word right
^pattern$, matches the entire line only the specified pattern
^$: Blank Line
^[[:blank:]]$: No visible characters for entire line
\<word\>: Match Whole word
Group
() enclose any character in parentheses to make a whole match.
Back reference: Apply the contents of the preceding grouping brackets, not the schema itself, \1,\2 ...
(TH). *\1: Matches what the first parenthesis matches
3.fgrep: Regular expressions are not supported, matching only the specified string
Fgrep [optings] patern File ...
Five. Regular expression grep, Egrep, Fgrep