歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> grep搜索匹配行前後幾行

grep搜索匹配行前後幾行

日期:2017/2/27 15:57:35   编辑:Linux教程
# man grep
-A NUM, --after-context=NUM
       Print  NUM  lines  of  trailing  context  after  matching lines.
       Places  a  line  containing  a  group  separator  (--)   between
       contiguous  groups  of  matches.  With the -o or --only-matching
       option, this has no effect and a warning is given.
-B NUM, --before-context=NUM
       Print NUM  lines  of  leading  context  before  matching  lines.
       Places   a  line  containing  a  group  separator  (--)  between
       contiguous groups of matches.  With the  -o  or  --only-matching
       option, this has no effect and a warning is given.

-C NUM, -NUM, --context=NUM
       Print  NUM  lines of output context.  Places a line containing a
       group separator (--) between contiguous groups of matches.  With
       the  -o  or  --only-matching  option,  this  has no effect and a
       warning is given.
$grep -5 'parttern' inputfile //打印匹配行的前後5行
 
$grep -C 5 'parttern' inputfile //打印匹配行的前後5行
 
$grep -A 5 'parttern' inputfile //打印匹配行的後5行
 
$grep -B 5 'parttern' inputfile //打印匹配行的前5行
Copyright © Linux教程網 All Rights Reserved