A summary of the usage of regularities and sed.
A summary of the usage of regularities and sed.
Generally use egrep
Egrep [option] "pattern" FILE
-v: display content other than the matching result
-I: ignore case
-o: show only the matching content (more commonly used)
-- color uses colors to display the matching content.
-A 1 means to match the line after the content: EX egrep-A 1'^ ssh' / etc/passwd means to match to the line that begins with SSH.
-B1 displays 1 line that matches to the front of the content
-C 1 indicates that one line before and after matching to the content
Egrep source characters:
+: indicates that the preceding character is matched at least once. Egrep-- color 'aroomb' / etc/fstab
| |: match | either side a | b means match a | b (a | b) c means ac or bc a | bc, which means an or bc. |
? Match 0 times or once
*: match the preceding characters any number of times
. Match the preceding characters once
. *: it means any character, any number of times, egrep "a. Roomb" / etc/fstab means to grab / etc/fstab a followed by any character one or more times. For example, a123b abb ab aab aiienwkjen23b meets the conditions.
(1) grouping, which can be used for backward references and is often used with {}
{npencil m} means to match the preceding character or word or phrase only n times, up to m times. Egrep'ab {1pc4} c'/ etc/fstab
EX / tmp/1 content is he like his liker
He love his like
He like his lover wants to match to the fourth word and end the second word with r.
Egrep "l (. *) e\ 1er" / tmp/1
Egrep-o "(\.) (3)" / etc/fstab