Grep用法日记

grep主要是用于从某个文件中或流中搜索。常用简单举例如下:

a.log

This is my pen!
This pen costs me 150 yuan
I have a mobile
My mobile num is 1501111
My fb is 4455
My qq is 1502222

匹配150的行

  grep '150' a.log

This pen costs me 150 yuan
My mobile num is 1501111
My qq is 1502222

显示匹配的第一个结果

  grep -m1 '150' a.log

This pen costs me 150 yuan

 

显示匹配的结果前后5行

  grep -5 '150' a.log

This is my pen!
This pen costs me 150 yuan
I have a mobile
My mobile num is 1501111
My fb is 4455
My qq is 1502222This 

 

匹配150的电话

  grep '150' a.log|grep 'mobile'

My mobile num is 1501111

 

posted @ 2018-07-31 13:57  举起希望之灯  阅读(275)  评论(0)    收藏  举报