[CLUE-Tech] vi search/replace question

David Anselmi anselmi at anselmi.us
Fri Apr 23 09:24:56 MDT 2004


Dave Price wrote:
[...]
> Is there a way to delete entire lines globbally from a file when part
> of the line matches a pattern?
> 
> For example, I want to remove all the lines the start with a particular
> character, perhaps #, (so the regex to find the lines would be ^# ...

:g /^#/ d

The colon means we're working in line mode.  g, or global, means "do to 
every line".  The the regex, lines starting with #.  Then d, or delete.

Line mode in vi is good stuff.  There's a tutorial that covers it better 
than most at:

http://www.nwc.com/unixworld/tutorial/009/009.html

Dave




More information about the clue-tech mailing list