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

Brian Blater brb.lists at gmail.com
Mon Jul 14 14:15:37 EDT 2008


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.

Well they all return "pattern not found".

Having failed to figure that out I'm not sure how to even go about the
next step which is this:

The file has several lines (of course) in the following format (but
artist and filename would be different):

../../../../../audiostuff/audio/Current (70's and newer)/Dexy's
Midnight Runners/Dexy's Midnight Runners - Come On Eileen.mp3

I want to delete everything except the filename - so I would have only
Dexy's Midnight Runners - Come On Eileen.mp3 on the line.

Since the beginning part is mostly the same I could just do a search
and replace for that without using a regexp, but how would I go about
searching and replacing the whole line with just the filename?

Thanks for any help you all can give me as I try to learn something
new. In the windows world I used to do this with some elaborate
wordperfect macros, but gone are those days.

Thanks,
Brian

ps - any good regexp tutorials out there I should grab a copy of?



More information about the TriLUG mailing list