Hi,

Eric Leenman schrieb:
> 
> I have a file where I deleted all lines that don't contain a certain pattern
> For example I want to delete all lines that don't contain XXX and YYY.
> 
> Before:
> 
> [start of file]
> abcde XXX fghij YYY
> 12345 AAA 67890 BBB
> klmno XXX pqrst YYY
> 09876 XXX 54321 BBB
> &*()- XXX ,./;' YYY
> [end of file]
> 
> After:
> [start of file]
> abcde XXX fghij YYY
> &*()- XXX ,./;' YYY
> [end of file]
> 
> 
> How do I do that?

  :g/PATTERN/d

deletes all lines that match a specific pattern. To keep all lines you
need to use

  :g!/PATTERN/d

or

  :v/PATTERN/d

Now your pattern is either

  XXX.*YYY

or

  XXX.*YYY\|YYY.*XXX

depending on wheter you only want to keep lines with contain XXX in
front of YYY or whether the order of those strings is irrelevant. So
the final command is

  :v/XXX.*YYY/d

or

  :v/XXX.*YYY\|YYY.*XXX/d

Regards,
Jürgen

-- 
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

Reply via email to