LinuxEye - Linux系统教程

LinuxEye - Linux系统教程

当前位置: 主页 > Linux教程 >

grep搜索匹配行前后几行

时间:2013-10-27 16:25来源:未知 编辑:linuxeye 点击:
# 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
# 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行

转载请保留固定链接: https://linuxeye.com/Linux/1963.html

------分隔线----------------------------
标签:grep
栏目列表
推荐内容