Regular expression is the way to deal with strings. It can perform specific character handlers such as find, delete, and replace.
Common commands grep, awk, sed
[: alunm:] represents English case characters and numbers, i.e. 0-9 A-Z a-z
[: alpha:] represents any English case letter A-Z A-Z
[: blank:] represents the space bar and the [Tab] key
[: Dark:] for 0-9
[: lower:] for lowercase characters and a-z
grep common daily usage
-i ignore case
-n output the line number of the lookup
-v reversely select and display the line without the content of the search string
"Open Source" is a good mechanism to develop programs.
apple is my favorite food.
Football game is not use feet only.
this dress doesn't fit me.
However, this dress is about $ 3183 dollars.^M
GNU is free air not free beer.^M
Her hair is very beauty.^M
I can't finish the test.^M
Oh! The soup taste good.^M
motorcycle is cheap than car.
This window is clear.
the symbol '*' is represented as start.
Oh! My god!
The gd software is a library for drafting programs.^M
You are the best is mean you are the no. 1.
The world <Happy> is the same with "glad".
I like dog.
google is the best tools for search keyword.
goooooogle yes!
go! go! Let's go.
# I am VBird
~
~
1. Find a specific string
[root@localhost tmp]# grep -n 'the' regular_express.txt
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 "glad".
18:google is the best tools for search keyword.
Ignore Case + i and reverse + v
2. Use [] to find set characters
Column if you want to find test and taste
[root@localhost tmp]# grep -n 't[ae]st' regular_express.txt
8:I can't finish the test.
9:Oh! The soup taste good.
3. Find out no lowercase characters before oo
[root@localhost tmp]# grep -b '[^a-z]oo' regular_express.txt
82:Football game is not use feet only.
4. Find the line beginning with the
[root@localhost tmp]# grep -n '^the' regular_express.txt
12:the symbol '*' is represented as start.
5 find the line ending with
[root@localhost tmp]# grep -n '\.$' regular_express.txt
1:"Open Source" is a good mechanism 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 "glad".
17:I like dog.
18:google is the best tools for search keyword.
20:go! go! Let's go.
Need to escape
6. Find blank lines
[root@localhost tmp]# grep -n '^$' regular_express.txt
22:
7. In regular expressions
(decimal point) means there must be an arbitrary character
*(asterisk) means to repeat the previous 0 to infinite times. It is a combination form
If you want to find g?? d string
[root@localhost tmp]# 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> is the same with "glad".
8. Find more than two o strings
[root@localhost tmp]# grep -n 'ooo*' regular_express.txt
1:"Open Source" is a good mechanism 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!
9. Find g String of G
[root@localhost tmp]# grep -n 'g.*' regular_express.txt
1:"Open Source" is a good mechanism to develop programs.
3:Football game is not use feet only.
13:Oh! My god!
16:The world <Happy> is the same with "glad".
17:I like dog.
18:google is the best tools for search keyword.
19:goooooogle yes!
20:go! go! Let's go.
Limit the number of duplicate characters matched in a range interval
10. Suppose to find a string of consecutive ooo
[root@localhost tmp]# 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 is not use feet only.
9:Oh! The soup taste good.
18:google is the best tools for search keyword.
19:goooooogle yes!
11. Match 3-5 oo
[root@localhost tmp]# grep -n 'o\{3,5\}' regular_express.txt
19:goooooogle yes!