正则表达式实例
文件内容:
I am oldboy teacher!
I teach linux.
Ilike badminto ball http:/www.baidu.com
my qq num is 412421412
I am oldboy teacher!
I teach linux.
I like badminton ball,billiard ball and chinese chess!
- my blog is http://oldboy.blog.51cto.com
- our site is http://www.etiantian.org
- my qq num is 444877
- not 44453434
my god,i am not oldbey,but OLDBOY!
1. 基础正则第一学
^word 匹配以 word 开头的内容.
word$ 匹配 word 结尾的内容.
^$ 表示空行
示例:
- [root@localhost kang]# grep "^m" test.txt #以 m 开头
- my blog is http://oldboy.blog.51cto.com
- my qq num is 444877
my god,i am not oldbey,but OLDBOY!
- [root@localhost kang]# grep "m$" test.txt #以 m 结尾
- my blog is http://oldboy.blog.51cto.com
- [root@localhost kang]# grep "^$" test.txt #输出空行
- [root@localhost kang]# grep -v "^$" test.txt #排除空行
来源: http://www.bubuko.com/infodetail-2592606.html