Monday, October 3, 2011

How to match lines containing patternA but not containing patternB?

Facing with a data file which contains more than 7 million lines, I need to delete all lines containing <patternA> but not containing <patternB>.
So far the only way I can think of is kind messy, something like this:
 
:g/<patternB>/s/<patternA>/<patternC>/
:g/<patternA>/d
:%s/<patternC>/<patternA>/
 
But I really like to know how this can be done in a better way, like a single global replacement command or something.
 
 

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: