PDA

View Full Version : [Question] How to remove all lines that contain certain text in VI



beyonddc
22nd August 2007, 03:58 PM
[Question] How to remove all lines that contain certain text in VI?

For example I've the following text.



Monday, Tuesday, Wednesday
Thursday Friday Saturday Sunday
Monday, Tuesday, Wednesday
Thursday Friday Saturday Sunday
Monday, Tuesday, Wednesday
Thursday Friday Saturday Sunday
Monday, Tuesday, Wednesday
Thursday Friday Saturday Sunday
Monday, Tuesday, Wednesday
Thursday Friday Saturday Sunday
Monday, Tuesday, Wednesday
Thursday Friday Saturday Sunday
Monday, Tuesday, Wednesday
Thursday Friday Saturday Sunday


I want to remove all line that contains the word "Monday". The end result should look like this. Of course I can do a search and then hit "dd" on each line but when I've a big document, this will be very painful.



Thursday Friday Saturday Sunday
Thursday Friday Saturday Sunday
Thursday Friday Saturday Sunday
Thursday Friday Saturday Sunday
Thursday Friday Saturday Sunday
Thursday Friday Saturday Sunday
Thursday Friday Saturday Sunday


Thanks!!!

LocutusOfBorg
22nd August 2007, 04:35 PM
try something like

:g/^Monday/d

pete_1967
22nd August 2007, 04:58 PM
Vim uses regular expressions in its search (and replace), below does what you are trying to do:


:%s/^Monday.*\n//g


Read more about regular expressions in Vim: http://larc.ee.nthu.edu.tw/~cthuang/vim/files/vim-regex/vim-regex.htm