does vi have a search/deletion macro???
Michael J. Chinni, SMCAR-CCS-E
mchinni at pica.army.mil
Sat Sep 9 00:17:17 AEST 1989
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 <string> <filename> )
> 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 at pica.army.mil
"System been down long?" () UUCP: ...!uunet!pica.army.mil!mchinni
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
More information about the Comp.unix.questions
mailing list