Find a specific string and color display
[Email protected] test]# grep-n ' the ' Regular_express.txt--color=auto
8:i can ' t finish the test.
12:the symbol ' * ' is represented as start.
15:you is the best was mean you are the No. 1.
16:the World <Happy> was the same with "glad".
18:google is the best tools for search keyword.
Reverse select to find a specific string and color display
[Email protected] test]# grep-vn ' the ' Regular_express.txt--color=auto
1: "Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
......
Ignore case to find specific characters
[email protected] test]# grep-in ' the ' regular_express.txt
Use [] to find the collection character:
[Email protected] test]# grep-n ' t[ae]st ' regular_express.txt
8:i can ' t finish the test.
9:oh! The soup taste good.
Look for a ' oo ' string
[Email protected] test]# grep-n ' oo ' regular_express.txt
1: "Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
3:football game isn't use feet only.
9:oh! The soup taste good.
18:google is the best tools for search keyword.
19:goooooogle yes!
Look for the ' oo ' string, but do not have g in front, that is, eliminate goo
[[email protected] test]# grep-n ' [^g]oo ' Regular_express.txt
2:apple is my favorite food.
3:football game isn't use feet only.
18:google is the best tools for search keyword.
19:goooooogle yes!
Find content with non-lowercase letters and OO
[[email protected] test]# grep-n ' [^a-z]oo ' Regular_express.txt
3:football game isn't use feet only.
Get a row with a number
[Email protected] test]# grep-n ' [0-9] ' regular_express.txt
5:however, this dress was about $3183 dollars.
15:you is the best was mean you are the No. 1.
[[email protected] test]# grep-n ' [^[:lower:]]oo ' Regular_express.txt
3:football game isn't use feet only.
Query for characters that begin with the
[Email protected] test]# grep-n ' ^the ' regular_express.txt
12:the symbol ' * ' is represented as start.
The query starts with a lowercase letter content
[Email protected] test]# grep-n ' ^[a-z] ' regular_express.txt
2:apple is my favorite food.
4:this dress doesn ' t fit me.
10:motorcycle is cheap than car.
12:the symbol ' * ' is represented as start.
18:google is the best tools for search keyword.
19:goooooogle yes!
20:go! Go! Let ' s go.
Query the first character is not uppercase
[Email protected] test]# grep-n ' ^[[:lower:] ' regular_express.txt
2:apple is my favorite food.
4:this dress doesn ' t fit me.
10:motorcycle is cheap than car.
12:the symbol ' * ' is represented as start.
18:google is the best tools for search keyword.
19:goooooogle yes!
20:go! Go! Let ' s go.
Query for characters that are not beginning with English
[Email protected] test]# grep-n ' ^[^a-za-z] ' regular_express.txt
1: "Open Source" is a good mechanism to develop programs.
21:# I am Vbird
The query ends with the contents of the line of the decimal point.
[Email protected] test]# grep-n ' \.$ ' regular_express.txt
1: "Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
3:football game isn't use feet only.
4:this dress doesn ' t fit me.
10:motorcycle is cheap than car.
11:this window is clear.
12:the symbol ' * ' is represented as start.
15:you is the best was mean you are the No. 1.
16:the World <Happy> was the same with "glad".
17:i like dog.
18:google is the best tools for search keyword.
20:go! Go! Let ' s go.
Find "Blank line"
[Email protected] test]# grep-n ' ^$ ' regular_express.txt
22:
Wildcard characters. and * use,. (decimal point) The representative must have an arbitrary character, * representing the meaning of repeating the previous one to an infinite number of times
[Email protected] test]# grep-n ' G.. d ' Regular_express.txt
1: "Open Source" is a good mechanism to develop programs.
9:oh! The soup taste good.
16:the World <Happy> was the same with "glad".
Query for any number of rows that appear
[ [email protected] test]# grep-n ' [0-9][0-9]* ' Regular_express.txt
5:however, this dress was about $3183 dollars.
15:you is the best was mean you are the No. 1.
The query appears with a string of two O
[[email protected] test]# grep-n ' o\{2\} ' regular_express.txt
1: "Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
3:football game isn't use feet only.
9:oh! The soup taste good.
18:google is the best tools for search keyword.
19:goooooogle yes!
The query appears with a string of 2-5 O, followed by a G string
[Email protected] test]# grep-n ' o\{2,5\}g ' regular_express.txt
18:google is the best tools for search keyword.
19:goooooogle yes!
The query appears with a string of more than 2 O, followed by a G string
[Email protected] test]# grep-n ' o\{2,\}g ' regular_express.txt
18:google is the best tools for search keyword.
19:goooooogle yes!
A detailed description of grep usage in Linux