Linux self-study journey-basic commands (basic regular expression with grep)
Article Directory
Preface
1. In the previous section, we briefly introduced the function and usage of the grep command. If you haven't read it yet, please click the link below to enter: grep
2. In this section, we talk about the use of basic regular expressions with grep in the shell
Tip: The following is the content of this article
1. The role of basic regular expressions in the shell
1. Those who have studied development should be familiar with regular expressions. For example, when we write a web page, there is a check box that requires users to enter a password. We can use regular expressions to restrict users to input, for example, the input mailbox must have an @ sign Duck or something. Regular expressions can also be used in our shell, which is very similar to wildcards, but wildcards are generally used to match file names, and our regular expressions are generally used to match strings, that is, it will cooperate with commands such as grep, awk, sed, etc. usage of.
2. Then regular expressions are divided into basic regular expressions and extended regular expressions in our shell.
Second, the use of basic regular expressions
1. What are the basic regular expressions?
2. Basic regular expression with grep
1. This paragraph means matching the content line starting with ^he in the file test
2. This paragraph means matching the content line ending with ds. in the test file
3. The first paragraph: means matching the content starting with B and the second character is The line of the content of u or a .
Second paragraph: It means to match the content line that starts with the number 5 and the second character is not an English letter .
4. The first paragraph: match the content line starting with h and the second character is a random character .
The second paragraph: match the beginning of the number 5, and then the next character as long as the 5 will match the content of the line .
5. The first paragraph: match the beginning of b, and then because we restrict b to appear at least once, and then at most once, so it is to match a line with the content at the beginning of b .
Second paragraph: match the beginning of b, and then we restrict b to only appear once, so it matches a content line beginning with b .
The third paragraph: Matches the beginning of the number 5, and then 5 appears at least once, so it is the line that matches the beginning of 5, and then as long as the following character is 5, it will match the content .
to sum up
In this section, we briefly understand some of the uses of basic regular expressions with grep, and we usually use regular expressions for filtering text content with grep.
This is Jiehua, see you next time!