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的数字))
阅读(1262) | 评论(0) | 转发(0) |