4, grep and regular expressions
1, grep program
under Linux Sed awk text processing trio --grep
grep-- line of text filtering tools
sed-- text line editor (stream editor)
awk-- report generator (do text output format)
1, grep program
under Linux Sed awk text processing trio --grep
grep-- line of text filtering tools
sed-- text line editor (stream editor)
awk-- report generator (do text output format)
grep contains three commands grep egrep fgrep used to line mode (pattern) matching
egrep = gerp -E // use extended regular expressions to match
fgrep = fast grep // use files matching the wildcard
* default regular expressions grep type text to match *
egrep = gerp -E // use extended regular expressions to match
fgrep = fast grep // use files matching the wildcard
* default regular expressions grep type text to match *
用法grep:
grep [option] ... PATTERN [pound name]
grep [option] ... PATTERN [pound name]
grep common options --option:
-E supports extended regular expression (ERE) (regexp)
-P with Perl regular expression search engine (every language of regular expression engine is not the same, even sed use grep awk engine is not the same)
-i ignore case
-v selected from anti
-o only output matching content (default output is matched to the line)
--color = Auto syntax coloring
-n line numbers
-E supports extended regular expression (ERE) (regexp)
-P with Perl regular expression search engine (every language of regular expression engine is not the same, even sed use grep awk engine is not the same)
-i ignore case
-v selected from anti
-o only output matching content (default output is matched to the line)
--color = Auto syntax coloring
-n line numbers
2, pattern "model" - regular expression
functions: through some special characters to represent a class character, and then to the front of the command to execute, if the special character itself, you need to \ escape
file wildcard *? [] [^]
1 character matches
. any one character equivalent?
[] Within a matching range of any character, the same file masks
[^] outside the matching range of any character, the same file wildcard
character classes: [: digit:] [: alnum:] [: alpha:] [: lower:] [: Upper:] [: Space:] [: punct:]
2, the number of match
* matches the preceding character zero to n times
\? Matches the preceding character zero to 1
\ + Matches the preceding character 1 to n times
\ {m \} matches the preceding character m times
\ {m, n \} matches the preceding character m to n times
\ {0, n \} matches the preceding character 0 to n times
\ {m, \} character match preceding least m
3, the position of the anchoring
^ anchors the first line
$ anchor end of a line
\ b anchor the first word and the anchoring suffix
\ > anchoring suffix
\ <Anchoring the first word
4, grouping
abc * abcccc abc needs as a whole
\ (\) example: \ (abc \) * ABCABCABC abcccc
** grouping characteristics: By default, Linux system will be designated as the grouping variable, variable representation \ 1 \ 2 \ 3 ...
functions: through some special characters to represent a class character, and then to the front of the command to execute, if the special character itself, you need to \ escape
file wildcard *? [] [^]
1 character matches
. any one character equivalent?
[] Within a matching range of any character, the same file masks
[^] outside the matching range of any character, the same file wildcard
character classes: [: digit:] [: alnum:] [: alpha:] [: lower:] [: Upper:] [: Space:] [: punct:]
2, the number of match
* matches the preceding character zero to n times
\? Matches the preceding character zero to 1
\ + Matches the preceding character 1 to n times
\ {m \} matches the preceding character m times
\ {m, n \} matches the preceding character m to n times
\ {0, n \} matches the preceding character 0 to n times
\ {m, \} character match preceding least m
3, the position of the anchoring
^ anchors the first line
$ anchor end of a line
\ b anchor the first word and the anchoring suffix
\ > anchoring suffix
\ <Anchoring the first word
4, grouping
abc * abcccc abc needs as a whole
\ (\) example: \ (abc \) * ABCABCABC abcccc
** grouping characteristics: By default, Linux system will be designated as the grouping variable, variable representation \ 1 \ 2 \ 3 ...
![](https://img2018.cnblogs.com/blog/1669051/201908/1669051-20190814172219580-2036489360.png)
2, logic statements
if
if
![](https://img2018.cnblogs.com/blog/1669051/201908/1669051-20190814172315856-2068591499.png)
for ---- --- list is not easy to enter an infinite loop into a for loop
while-- into the specified loop condition is True cycle
until-- specify the conditions for entering circulation loop is False (do not enter an infinite loop)
case-- write LInux program startup script
to interrupt the cycle
BREAK
the Continue
exit - Specifies the exit program was
read - input () input
echo - print () output