1. grep: Global RE Printing
Regular Expression
Text filtering tool, which can perform row-by-row search based on the specified pattern)
The content of the file and the matched lines are displayed;
Mode: it is a matching condition consisting of metacharacters of regular expressions and other characters;
RE: Regular Expression
Base RE
Extended RE
Grep [option]... 'pattern' FILE...
-V reverse value;
-- Color = auto-matched characters are displayed in red and bold;
1. Basic Regular Expression metacharacters
.: Match any single character;
For example, grep 'C. U'/proc/cpuinfo;
..: Match 2 characters;
[]: Any single character in the specified range;
For example, grep -- color = auto'c .. [a-z] '/proc/cpuinfo;
[^]: Any character out of the specified range;
2. Times matching greedy match)
*: Match the first character 0, 1 or multiple times;
For example, AB * c: abc, abbc, and ac do not match.) abdc (indicating the appearance of B
Times );
Job (grep.txt file, one of which has the tab key ):
Find AB, a B, accccb;
Grep 'a [[: space:] * B '/tmp/grep.txt;
? : Match the first character 0 or 1 time;
\ {M, n \}: Where \ is conversion, {} is to avoid shell expansion, at least m
N times at most;
\ {M, \}: At least m times;
\ {0, n \}: up to n times;
\ {M \}: m times;
Job:
Exercise the following match:
A [a-z] \ {0, 2 \} c: abc, aaaac, accccc;
3. Anchor
R.. t: root, chroot, rooter;
This is root.
There is chroot.
Word anchoring:
\ <: The beginning of the anchor; for example, \ <r. t;
\>: Specifies the end of a word, for example, root \>;
First line anchored:
^ Escape Character): for example, ^ root;
Anchor at the end of the line:
$: For example, root $;
Job:
A. How to display the rows whose end is root and can contain a punctuation mark;
Grep 'root [[: punct:]? $ 'File = grep' root [[: punct:] \ {0, 1 \} $ 'file;
B. How to display blank rows starting with "root;
Grep '^ [[: space:] * root 'file;
. *: Match any character of any length;
For example, a. * B, a and B can contain any character of any length;
4. Group
Xabababy and AB appear in groups;
\ (\), X \ (AB \) * y
Forward reference:
He love his lover.
She like her liker.
He love his liker.
She like her lover.
L. e. * l.. er;
\ (L. e \). * \ 1r is followed by a number 1 );
This article is from the blog "Nick Liu's blog", please be sure to keep this source http://zkhylt.blog.51cto.com/3638719/1301589