1. 程式人生 > >Linux 之 正則表達式實例

Linux 之 正則表達式實例

正則表達式

正則表達式實例
文件內容:
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     #排除空行

Linux 之 正則表達式實例