Article Directory
grep (global search regular expression(RE) and print out the line, search for regular expressions and print out the line) is a powerful text search tool that can search for text using regular expressions and print out the matching lines come out
1. Detailed explanation of grep command parameters
Command format:grep 匹配条件 处理文件
grep -E = egrep #命令相同
|
Ignore case filtering |
|
No characters before the filter text |
|
No characters after the filter text |
|
Show the filter line and the upper and lower lines |
|
Display the line number of the matched line |
|
Show the filter line and the lines above |
|
Show the filter line and the following lines |
|
Reverse filter |
|
Only output the matched part of the file |
1.1 grep command usage example
1 Filter multiple texts at the same time
2 Ignore case filter
3 Specify the text as the beginning or end to filter
4 Display the line number of the matched line
5 Display the filter line and the upper or lower lines
6 reverse filtering
2. Grep character number matching rules
|
Start with this text |
|
End with this text |
|
Start with w and end with 2 arbitrary characters in the middle |
|
End with s, any 5 characters in front |
|
Any character |
|
0-1 times |
|
1- any time |
|
n times |
|
mn times |
|
0-n times |
|
At least m times |
|
How many times the text appears |
2.1 Example of grep character limit
1 Specify the beginning or end of the text
2 Specify any characters apart
3. Practice script: display the names of users in the system that can be switched by the su command
grep -E "bash$|sh$" /etc/passwd | cut -d : -f 1