Chinaunix首页 | 论坛 | 博客
  • 博客访问: 63868
  • 博文数量: 16
  • 博客积分: 298
  • 博客等级: 二等列兵
  • 技术积分: 135
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-30 06:11
文章分类
文章存档

2013年(1)

2011年(15)

分类: Python/Ruby

2011-08-11 20:23:40

1)匹配(the)单词的行:
 [root@localhost ~]# cat textfile
This is line 1, of which there is only one instance.
This is the only instance of line 2.
This is line 3, another line.
This is line 4.
[root@localhost ~]# grep 'the' textfile
This is line 1, of which there is only one instance.
This is the only instance of line 2.
This is line 3, another line.
[root@localhost ~]# grep '\' textfile
This is the only instance of line 2.

&问号(?):匹配零个或一个前面的字符 ;加号(+):匹配一个或多个前面的字符
 # sed and awk 可以使用"+",但需要转义下
[root@localhost ~]# echo a111b | sed -n '/a1\+b/p'
a111b
[root@localhost ~]# echo a111b | grep 'a1\+b'
a111b
[root@localhost ~]# echo a111b | awk '/a1+b/'
a111b
[root@localhost ~]# echo a111b | grep -E 'a1+b'
a111b

&--\{\}:指前面正则表达式匹配的次数([0-9]\{5\}精确匹配5个数字(从0到9的数字))
阅读(1221) | 评论(0) | 转发(0) |
0

上一篇:Mysql 学习笔记

下一篇:正则表达式元字符

给主人留下些什么吧!~~