How to exclude several lines around match with grep or similar tool?

爱⌒轻易说出口 提交于 2019-11-28 09:46:49

问题


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?


回答1:


You can use the vim text editor:

:g/my_pattern/-2,//+2d


来源:https://stackoverflow.com/questions/9442014/how-to-exclude-several-lines-around-match-with-grep-or-similar-tool

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!