How to exclude several lines around match with grep or similar tool?
I can find all non-matched lines of file with grep -v 'my_pattern' some_file
. Also i can print few strings before/after/around match with -A
, -B
or -C
options of grep. But i can't combine these two options to exclude lines with pattern and certain amount of lines near matched lines - grep shows entire file as result. For example, i have log with a lot of patterns like this:
25.02.2012 10:41:37 here goes memory state
25MiB free
16MiB allocated
max free block is 4MiB
I'd like to filter them. Of course, i can write custom perl/awk script, but is there more elegant way to do this?
你可以使用vim
文本编辑器:
:g/my_pattern/-2,//+2d
链接地址: http://www.djcxy.com/p/19696.html
上一篇: PowerShell是否准备好替换Windows上的Cygwin shell?
下一篇: 如何排除与grep或类似工具匹配的几行?