1.下载模板问题
[root@test001 ~]# wget http://linux.vbird.org/linux_basic/0330regularex/regular_express.txt
[root@test001 ~]# vim regular_express.txt
"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
文件共22行最下面行为空格。我们开始吧
1.搜索指定字符串
[root@test001 tmp]# grep 'the' regular_express.txt
I can't finish the test.
the symbol '*' is represented as start.
You are the best is mean you are the no. 1.
The world <Happy> is the same with "glad".
google is the best tools for search keyword.
2.取反数值
[root@test001 tmp]# grep -vn "the" 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.
5:However, this dress is about $ 3183 dollars.
6:GNU is free air not free beer.
7:Her hair is very beauty.
9:Oh! The soup taste good.
10:motorcycle is cheap than car.
11:This window is clear.
13:Oh! My god!
14:The gd software is a library for drafting programs.
17:I like dog.
19:goooooogle yes!
20:go! go! Let's go.
21:# I am VBird
22:
不论大小写取'the'值
[root@test001 tmp]# grep -vn "the" 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.
5:However, this dress is about $ 3183 dollars.
6:GNU is free air not free beer.
7:Her hair is very beauty.
9:Oh! The soup taste good.
10:motorcycle is cheap than car.
11:This window is clear.
13:Oh! My god!
14:The gd software is a library for drafting programs.
17:I like dog.
19:goooooogle yes!
20:go! go! Let's go.
21:# I am VBird
22:
搜索集合
[root@test001 tmp]# grep -n "t[ae]st" regular_express.txt
8:I can't finish the test.
9:Oh! The soup taste good.
不想要oo字段前面有g
[root@test001 tmp]# grep -n "t[ae]st" regular_express.txt
8:I can't finish the test.
9:Oh! The soup taste good.
[root@test001 tmp]# 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!
不想要oo字段前面有小写字母
[root@test001 tmp]# grep -n "[^a-z]oo" regular_express.txt
3:Football game is not use feet only.
只要有数字的行
[root@test001 tmp]# 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.
取行首“the”的行
[root@test001 tmp]# grep -n "^the" regular_express.txt
12:the symbol '*' is represented as start.
不想要开头的英文字母
[root@test001 tmp]# grep "^[^a-zA-Z]" regular_express.txt
"Open Source" is a good mechanism to develop programs.
# I am VBird
查找以 " . " 结尾的字段
[root@test001 tmp]# grep "\.$" regular_express.txt
"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.
motorcycle is cheap than car.
This window is clear.
the symbol '*' is represented as start.
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.
go! go! Let's go.
匹配空行
[root@test001 tmp]# grep -n "^$" regular_express.txt
22:
不匹配空行以及#开头的行
[root@test001 tmp]# grep -v "^$" regular_express.txt | grep -v "^#"
"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.
GNU is free air not free beer.
Her hair is very beauty.
I can't finish the test.
Oh! The soup taste good.
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.
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.
任意一个字符“ . ” 与重复字符 “ * ”
[root@test001 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".
查找 g开头与g结尾并且两个g之中最少要有一个o
[root@test001 tmp]# grep -n "goo*g" regular_express.txt
18:google is the best tools for search keyword.
19:goooooogle yes!
想要找出g开头与g结尾得字符串,当中得字符可有可无
[root@test001 tmp]# grep -n "g*g" regular_express.txt
1:"Open Source" is a good mechanism to develop programs.
3:Football game is not use feet only.
9:Oh! The soup taste good.
13:Oh! My god!
14:The gd software is a library for drafting programs.
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.
找出g开头与g结尾之间1个或者多个字符
[root@test001 tmp]# grep -n "g.*g" regular_express.txt
1:"Open Source" is a good mechanism to develop programs.
14:The gd software is a library for drafting programs.
18:google is the best tools for search keyword.
19:goooooogle yes!
20:go! go! Let's go.
找出任意数字的行列
[root@test001 tmp]# 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.
限定连续RE字符范围{ }
找到两个o的字符串
[root@test001 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!
g后面2-5个o并且结尾是g
[root@test001 tmp]# grep -n "go\{2,5\}g" regular_express.txt
18:google is the best tools for search keyword.
查找两个o以上的goooo....里
[root@test001 tmp]# grep -n "go\{2,\}" regular_express.txt
1:"Open Source" is a good mechanism to develop programs.
9:Oh! The soup taste good.
18:google is the best tools for search keyword.
19:goooooogle yes!
网友评论