Thursday, January 23, 2014

how to delete lines containing a pattern and not containing another pattern?

 

I'm a long-time vi(m) user and I have question.

Can I remove lines that contain a pattern but not another pattern?

For example,

 

Line 1 : rabbit

Line 2 : arch sparc

Line 3 : arch arm

Line 4 : tiger

I want to remove lines containing arch but not containing sparc.

So Here I want to remove only line 3 leaving lines 1, 3 and 4 intact.

 

I can remove lines containg 'arch' by

:g/arch/d

I can remove lines not containing 'sparc' by

:g!/sparc/d

How do I combine those two?

I tried

:g/arch/&!/sparc/d  or :g/arch&!sparc/d

But of course it doesn't work. (with escape before ! also)

Is there a way to remove only line 3? I looked it up in the manual but in vain..

Thank you!

-------------------------------------------------------------------------

김찬, 책임연구원

한국전자통신연구원 융합기술연구부문 멀티미디어프로세서연구실

Chan Kim, Principal Researcher

ETRI (Electronics and Telecommnications Research Institute)

O)+82-42-860-5773  C) +82-10-3418-9152

E)ckim@etri.re.kr       web) http://chankim.dothome.co.kr

 
 

No comments: