Keep lines that end with a /

Find, replace, find in files, replace in files, regular expressions

Keep lines that end with a /

Postby Merlin » Wed Jun 21, 2006 8:39 pm

I have a huge list of lines and need to keep only the lines that have a trailing forwardslash /

Also, what would be the code to remove all lines that contain a trailing forward slash?

Example:

abc/abc/abc/ ***has trailing forwardslash
abc/abc/abc/filename.txt ***does not have trailing forwardslash
User avatar
Merlin
Basic User
Basic User
 
Posts: 16
Joined: Thu Aug 25, 2005 11:00 pm

Re: Keep lines that end with a /

Postby Mofi » Thu Jun 22, 2006 6:21 am

See Delete all lines not starting with a special phrase how to do it manually or use the first macro from this forum thread and replace the line

Find MatchCase RegExp "%Starting phrase*^p"
by
Find RegExp "%*/^p"


Or use the macro at How to delete all lines not containing specific word or string or expression? with UnixReOff and replace the line

Find "[images]"
by
Find RegExp "/$"
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4039
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Keep lines that end with a /

Postby Merlin » Thu Jun 22, 2006 5:47 pm

That works for a starting phrase, but I need something that will look at the last character and then if it is != to a forwardslash, then delete the line.

For the example file:
abc/abc/abc/
abc/abc/abc/filename.txt

The code you posted does not flag either line as one that contains a forwardslash. I tried placing a "/" inside the find, but that didn't work.
User avatar
Merlin
Basic User
Basic User
 
Posts: 16
Joined: Thu Aug 25, 2005 11:00 pm

Re: Keep lines that end with a /

Postby Merlin » Fri Jun 23, 2006 12:10 am

Hmmm.. I just tried again to search for %*/^p and it picked up every line. Not sure why this didn't work before.

I basically did a find that line, and replace it with some odd text combination, and then did a find the off text combo, and replace it with blank to delete it. Looks like it worked :)
User avatar
Merlin
Basic User
Basic User
 
Posts: 16
Joined: Thu Aug 25, 2005 11:00 pm


Return to Find/Replace/Regular Expressions