1, grep procedures
have the text processing Linux trio --grep, Sed, awk
grep: line of text filtering tools
sed: text line editor (stream editor)
awk: report generator (do formatting text output)
grep:
contains three commands: grep, egrep, fgrep, which are used for line mode (pattern) matching
egrep = grep -E // use extended regular expressions to match
fgrep = fast grep // use files wildcards matching
* grep default use regular expressions to match text *
grep usage:
grep [the option] ... the PATTERN [filename]
grep common options --option:
-E supports extended regular expression (ERE) (regexp )
-P use perl regular expression language search engine (positive every language expression engine is not the same, even sed, awk, use the regexp engine is not the same)
-i ignore case
-v anti-election
- o output only matching content (default output is matched to the line)
--color = Auto syntax coloring
-n line numbers
-w match fixed word
PATTERN-- regular expression
functions: through some special characters to represent a class character, and then to the front of the command to execute; if you use special characters, meaning itself is required \ to escape.
Review: file wildcard (globbing)
* any character? Any single character [] any single character within the brackets [^]: negated
1, character match
. Any one character
[] within the scope of any single character
[^] outside the range of any single character
2, the number of matching
* former matches a character 0 times to the n-th
\? Matches the preceding character zero to 1
\ + Matches the preceding character 1 to n times
\ {m \} previous character matches m times
A \ {. 7 \} AAAAAAA
\ {m, n \} character m before match to n times
\ {m, \} character before a match at least m times
3、位置锚定
^ 锚定行首
$ 锚定行尾
\b 锚定单词词首和锚定词尾
\> 锚定词尾
\< 锚定词首