Usage of grep commands in Linux
Usage of grep commands in Linux
Search for a specific string and display the color
[Root @ www.bkjia.com] # grep-n 'the 'regular_express.txt -- color = auto
8: I can't finish the test.
12: the symbol '*' is represented as start.
15: You are the best is mean you are the no. 1.
16: The world <Happy> is the same with "gglad ".
18: google is the best tools for search keyword.
Select to search for a specific string in reverse direction and display the color
[Root @ www.bkjia.com] # grep-vn 'the 'regular_express.txt -- color = auto
1: "Open Source" is a good mechanic to develop programs.
2: apple is my favorite food.
......
Ignore case sensitive characters
[Root @ www.bkjia.com] # grep-in the 'regular_express.txt
Use [] to find the collection characters:
[Root @ www.bkjia.com] # grep-n't [AE] st'regular_express.txt
8: I can't finish the test.
9: Oh! The soup taste good.
Search for strings with 'oo'
[Root @ www.bkjia.com] # grep-n 'oo 'regular_express.txt
1: "Open Source" is a good mechanic to develop programs.
2: apple is my favorite food.
3: Football game is not use feet only.
9: Oh! The soup taste good.
18: google is the best tools for search keyword.
19: goooooogle yes!
Find a string with a 'oo ', but do not have a g before, that is, remove goo
[Root @ www.bkjia.com] # grep-n' [^ g] oo 'regular_express.txt
2: apple is my favorite food.
3: Football game is not use feet only.
18: google is the best tools for search keyword.
19: goooooogle yes!
Search for non-lowercase letters and oo content
[Root @ www.bkjia.com] # grep-n' [^ a-z] oo 'regular_express.txt
3: Football game is not use feet only.
Obtain a row with numbers
[Root @ www.bkjia.com] # grep-n '[0-9] 'regular_express.txt
5: However, this dress is about $3183 dollars.
15: You are the best is mean you are the no. 1.
[Root @ www.bkjia.com] # grep-n '[^ [: lower:] oo 'regular_express.txt
3: Football game is not use feet only.
Query the characters starting with
[Root @ www.bkjia.com] # grep-n '^ the 'regular_express.txt
12: the symbol '*' is represented as start.
Queries content starting with lowercase letters
[Root @ www.bkjia.com] # 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.
The first character of the query is not in uppercase.
[Root @ www.bkjia.com] # 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 is not a character that starts with English
[Root @ www.bkjia.com] # grep-n '^ [^ a-zA-Z] 'regular_express.txt
1: "Open Source" is a good mechanic to develop programs.
21: # I am VBird
The content of the row ending with the decimal point.
[Root @ www.bkjia.com] # grep-n '\. $ 'regular_express.txt
1: "Open Source" is a good mechanic to develop programs.
2: apple is my favorite food.
3: Football game is not 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 are the best is mean you are the no. 1.
16: The world <Happy> is the same with "gglad ".
17: I like dog.
18: google is the best tools for search keyword.
20: go! Go! Let's go.
Search for blank lines"
[Root @ www.bkjia.com] # grep-n '^ $ 'regular_express.txt
22:
Wildcard. And * usage,. (decimal point) indicates that there must be an arbitrary character, * Indicates repeating the previous one to an infinite number of times.
[Root @ www.bkjia.com] # grep-n 'G.. d' regular_express.txt
1: "Open Source" is a good mechanic to develop programs.
9: Oh! The soup taste good.
16: The world <Happy> is the same with "gglad ".
Query the rows and columns with any numbers
[Root @ www.bkjia.com] # grep-n '[0-9] [0-9] * 'regular_express.txt
5: However, this dress is about $3183 dollars.
15: You are the best is mean you are the no. 1.
Query strings with two o Records
[Root @ www.bkjia.com] # grep-n 'o \ {2 \} 'regular_express.txt
1: "Open Source" is a good mechanic to develop programs.
2: apple is my favorite food.
3: Football game is not use feet only.
9: Oh! The soup taste good.
18: google is the best tools for search keyword.
19: goooooogle yes!
Query the strings with 2-5 o Records, followed by a string of g.
[Root @ www.bkjia.com] # grep-n 'o \ {2, 5 \} G' regular_express.txt
18: google is the best tools for search keyword.
19: goooooogle yes!
Query strings with more than 2 o Records followed by a string with a g ID
[Root @ www.bkjia.com] # grep-n 'o \ {2, \} G' regular_express.txt
18: google is the best tools for search keyword.
19: goooooogle yes!
Grep uses concise and Regular Expressions
Shell programming in Linux -- basic use of the grep command
Grep command details and related examples
Linux basic commands-grep
Set grep to highlight matching items
Linux grep command learning and summary
This article permanently updates the link address: