正则表达式 & grep

image

 

image

image

 

查找总共10个字符 & z结尾的行。

[root@sky ~]# grep "^.\{9\}z$"  /usr/share/dict/words
Abdul-Aziz
Austerlitz
chattererz
chervonetz
Rabinowitz
razzmatazz
roquellorz
Rosenkranz
tau-saghyz
[root@sky ~]#

查找a/b/c开头 & 21位是s的行

[root@sky ~]# grep "^[a,b,c]...................s"  /usr/share/dict/words
all-comprehensiveness
antienvironmentalists
antiinstitutionalists
bras-dessus-bras-dessous
brigantinebrigantines
chlamydobacteriaceous
clothes-consciousness
counterdemonstrations
counterproductiveness
[root@sky ~]#

查找两位数字开头的行:

[root@sky ~]# grep "^[0-9][0-9]"  /usr/share/dict/words
1080
10-point
10th
11-point
12-point
16-point
18-point
20-point
30-30
48-point
[root@sky ~]#

查找a/b/c开头,不是a/b/c结尾的行:

[root@sky ~]# grep "^[a,b,c][^a,b,c]$"  /usr/share/dict/words
a'
a-
a.
a1
ad

查找a/b/c开头,大写字母结尾的行:

[root@sky ~]# grep "^[a-c].*[A-Z]$"  /usr/share/dict/words
chloramine-T
cS
[root@sky ~]#

 

image

posted @ 2015-12-02 17:13  skyfly0772  阅读(212)  评论(0编辑  收藏  举报