Lesson 6 of my Longco operation and maintenance staff (1)
Text processing three Musketeers
Grep Department: grep, egrep, fgrep, text search tools, located in the "PATTERN" to conduct fuzzy search for a given text.
Sed:tream EDitor, stream editor, line editor, text editing tool
Awk:gawk--GNU awd, text formatting tool, text report generator, editing language for text processing
Grep system: grep, egrep, fgrep
Grep:Global search REgular expression and Print out the line.
Use the addition expression to conduct a global search and display the matching lines
Format: grep [OPTIONS] PATTERN [FILE...]
PATTERN: the filter condition consists of regular expression metacharacters and text characters that have no special meaning.
Metacharacters of regular expressions: are interpreted as special meanings by the regular expression engine; the regular expression engine of the pcre--perl language; where regular expressions are divided into two categories:
1. Basic regular expression: BRE
2. 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 regular expressions by default.
Text characters: characters that have only the superficial meaning of the characters
Common options:
-imam: ignore the case of text characters
-vmam talk match: direction match; the final result is a row that PATTERN does not match
-cmam Mutual account: count and count all the rows that match PATTERN
-thing: turn off greed mode and show only what PATTERN can match.
-QQuiet.com: quiet mode, no matching results are output
-- color [= WHEN],-- colour [= WHEN]: highlight content that matches PATTERN in a special color
-Emam grep talk: extended regular expression, Emam-E is equivalent to egrep
-Freguipr fgrep-F is equivalent to Fleming.
Basic egrep regexp: basic regular expression, Gmam-G equals grep
The PCRE (Perl Regular Expression) engine is used.
-A NUM,--after-context=NUM: displays the following NUM lines while displaying the lines that match the PATTERN
-B NUM,-- before-context=NUM: displays the previous NUM line while displaying the line that matches the PATTERN
-C NUM,-NUM,-- context=NUM: display the NUM lines before and after the lines that match the PATTERN
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:] 、 [: alnum:] 、 [: punct:] 、 [: blank:]
[: xdigit:]: all hexadecimal numbers
Amurz: all lowercase letters
Amurz: all capital letters
0-9: identifies all decimal digits
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 or 1)
\ +: the character preceding it appears at least once (1 or more times)
\ {m\}: the character before it must appear m times
\ {mdirection n\}: the character preceding it appears at least m times and at most n times; (m