码迷,mamicode.com
首页 > 其他好文 > 详细

正则表达式 & grep

时间:2015-12-02 18:26:07      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

技术分享

技术分享

 

查找总共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
aa-
a.
a1
ad

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

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

 

技术分享

正则表达式 & grep

标签:

原文地址:http://www.cnblogs.com/skyfly0772/p/5013575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!