[root@centos6 ~]# cat ansheng.txt My name is quiet!I am a Linux Operation and Maintenance EngineerMy youth will stay at eighteenI Hexo + Github made a static blog, blog address is: https://ansheng.meMy mail: as@ansheng.meQQ: 6087414Thank you!
符号
说明
^My
搜索以My开头的
1234
[root@ansheng ~]# grep --color=auto "^My" ansheng.txt My name is quiet!My youth will stay at eighteenMy mail: as@ansheng.me
符号
说明
me$
搜索以me结尾的
123
[root@ansheng ~]# grep --color=auto "me$" ansheng.txt I Hexo + Github made a static blog, blog address is: https: //ansheng.meMy mail: as@ansheng.me
符号
说明
^$
表示空格
12345678
[root@ansheng ~]# grep -vn --color=auto "^$" ansheng.txt 1:My name is quiet!2:I am a Linux Operation and Maintenance Engineer3:My youth will stay at eighteen4:I Hexo + Github made a static blog, blog address is: https: //ansheng.me5:My mail: as@ansheng.me6:QQ: 60874147:Thank you!
符号
说明
.
代表且只能代表任意一个字符
12345678
[root@ansheng ~]# grep --color=auto "." ansheng.txt My name is quiet!I am a Linux Operation and Maintenance EngineerMy youth will stay at eighteenI Hexo + Github made a static blog, blog address is: https: //ansheng.meMy mail: as@ansheng.meQQ: 6087414Thank you!
全部都过滤出来了!
符号
说明
\
转义符,让有着特殊意义的字符变成没有任何意义的字符
123
[root@ansheng ~]# grep --color=auto "\." ansheng.txt I Hexo + Github made a static blog, blog address is: https: //ansheng.meMy mail: as@ansheng.me
只过滤包含.的行
符号
说明
*
重复0个或者多个前面的一个字符
12345678
[root@ansheng ~]# grep --color=auto "0*" ansheng.txt My name is quiet!I am a Linux Operation and Maintenance EngineerMy youth will stay at eighteenI Hexo + Github made a static blog, blog address is: https: //ansheng.meMy mail: as@ansheng.meQQ: 6087414Thank you!
符号
说明
.*
匹配任意字符
12345678
[root@ansheng ~]# grep --color=auto ".*" ansheng.txt My name is quiet!I am a Linux Operation and Maintenance EngineerMy youth will stay at eighteenI Hexo + Github made a static blog, blog address is: https: //ansheng.meMy mail: as@ansheng.meQQ: 6087414Thank you!
.匹配的是任意一个字符,.*匹配的是任意0个或者个多个,所以才会有空行
符号
说明
[abc]
匹配字符集合内的任意一个字符
1234567
[root@ansheng ~]# grep --color=auto "[abc]" ansheng.txt My name is quiet!I am a Linux Operation and Maintenance EngineerMy youth will stay at eighteenI Hexo + Github made a static blog, blog address is: https: //ansheng.meMy mail: as@ansheng.meThank you!
符号
说明
[^abc]
匹配不包含^后的任意字符的内容
12345678
[root@ansheng ~]# grep --color=auto "[^abc]" ansheng.txt My name is quiet!I am a Linux Operation and Maintenance EngineerMy youth will stay at eighteenI Hexo + Github made a static blog, blog address is: https: //ansheng.meMy mail: as@ansheng.meQQ: 6087414Thank you!