Home   >>   Vi   >>   Vi Search and Delete Lines
Vi Search and Delete Lines PDF Print E-mail
( 1 Vote )
How To - Vi
Written by Christian Foronda   
Wednesday, 01 September 2010 08:58

"[ESC]" is the "Escape" key.
"%" is shorthand for "all lines".

Deletes all lines containing the word "junk":

	[ESC]:%g/junk/d

 

Deletes all lines containing apples, oranges or grapes:

	[ESC]:% ! egrep -v "(apples|oranges|grapes)"

Search and delete lines 50 through 100:

	[ESC]:50,100/junk/d

 

Remove DOS ^M from ends of lines:

	[ESC]:%s/<Ctrl-V><Ctrl-M>//g



blog comments powered by Disqus
Last Updated on Tuesday, 18 January 2011 09:13