Linux学习之路我用 LinuxLinux

grep:找出匹配行和前后的行

2018-05-25  本文已影响58人  whisshe

问题详情

需要统计nginx的访问日志中在某个时间点之后的IP以及IP的出现次数。于是可以先根据时间定位到某个时间点,再将该时间点之后的IP提取出来,统计出现次数。

解决方法

grep时Linux下非常好用的文本处理工具,功能非常强大。

Context Line Control
   -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.
上一篇 下一篇

猜你喜欢

热点阅读