Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!uakari.primate.wisc.edu!aplcen!haven!adm!xadmx!mchinni@pica.army.mil From: mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) Newsgroups: comp.unix.questions Subject: Re: does vi have a search/deletion macro??? Message-ID: <20802@adm.BRL.MIL> Date: 8 Sep 89 14:17:17 GMT Sender: news@adm.BRL.MIL Lines: 33 Peter, You wrote: > What I want to do is actually two-fold. > 1) How can I search for a string and have all occurrences show > on my screen (aside from doing a :!grep -i ) > because then I want to.... > 2) delete all lines which match the above mentioned search. One way to do this is via ex from inside vi. For instance, if the string is "tornado watch" the command to print AND delete all lines with this string is: :g/tornado watch/dp This says: invoke ex ( : ) globally ( g ) search for the expression "tornado watch" ( /tornado watch/ ) delete all matching lines ( d ) print all matching lines ( p ) I suggest doing this as two separate commands (i.e. :g/tornado watch/p then :g/tornado watch/d ). This will allow you to be sure that your search string will only match the lines you really want to delete and not others inadvertently. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Michael J. Chinni Chief Scientist, Simulation Techniques and Workplace Automation Team US Army Armament Research, Development, and Engineering Center User to skeleton sitting at cobweb () Picatinny Arsenal, New Jersey and dust covered workstation () ARPA: mchinni@pica.army.mil "System been down long?" () UUCP: ...!uunet!pica.army.mil!mchinni /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/