[TriLUG] Help with search and replace in vi using regexp

Steve Litt slitt at troubleshooters.com
Tue Jul 15 14:10:41 EDT 2008


On Monday 14 July 2008 14:15, Brian Blater wrote:
> I'm trying to do a search and replace in a text file using vi and a
> regexp and just not getting my arms around it. I've never really tried
> using regexp before (except for something someone had already
> configured and passed on to me.) So, I hit the net and did some
> searches on how to use vi and regexp and I'm just not getting it to
> work.
>
> So, here is what I've done. I've got an .m3u file that I'm using for
> testing my regexp skills and this is what I want to do:
>
> I want to search for each line that begins with #EXT and is followed
> by any number of visible characters or spaces and delete that line. In
>
> vi I put the following:
> :%s/\#EXT([\x20-\x7E]*)$//g or several other iterations using [0-9a-zA-Z]*
> : etc.

Without commenting on your regex, if you want to delete you should use the 
global command:

:g/searchstring/d

SteveT
 
Steve Litt
Recession Relief Package
http://www.recession-relief.US




More information about the TriLUG mailing list