Page 1 of 1
DELETE EVERYTHING BUT
Posted: Sun Jan 28, 2007 8:45 pm
by martib
Hallo,
I have a huge file and i want to delete all lines which
do not start with: a href="
http://www.
Any idea how to do that?
Posted: Sun Jan 28, 2007 9:42 pm
by Bob Hansen
1. Mark all lines that begin with "a href.......
Find:
^a href="http://www\..*
(Regular Expressions, POSIX syntax)
2. Toggle bookmarked lines
Search/Invert all bookmarks
3. Delete bookmarked lines
Edit/Delete/Bookmarked lines
========================================
Edited note, as caught by MudGuard:
The solution provided above will work in TextPad, not in WildEdit.
I did not notice that the question was in the WildEdit forum.
Sorry about that. Thanks MudGuard.
See his WildEdit solution that follows.......
Posted: Sun Jan 28, 2007 10:24 pm
by MudGuard
Bob, your solution would be ok if the posting did not appear in the WildEdit board ...
For wildedit:
search for any line:
^.*\n
Ok, replacing this would delete all lines. So we have to exclude the lines matching a certain expression.
For that, we use a negative lookahead assertion at the beginning of the line:
^(?!whatever).*\n
This will find any line not matching "whatever".
Replace these with nothing ==> all lines not starting with "whatever" will be gone.
Posted: Sun Jan 28, 2007 10:39 pm
by Bob Hansen
Aaargh!
Thanks MudGuard. I have done this more than once.
Thanks for catching that, I will modify the posting to mention that.
Posted: Sun Jan 28, 2007 11:08 pm
by ben_josephs
MudGuard wrote:^(?!whatever).*\n
Make sure that
[X] Regular expression
and
Options
[X] '.' does not match a newline character
are selected.
Posted: Wed Jan 31, 2007 12:19 am
by martib
thanks for all the help,
but even with the correct options nothing was deleted.
^(?!a href).*\n
^(?!a ).*\n
^(?!href).*\n
none of them worked
Posted: Wed Jan 31, 2007 9:34 am
by ben_josephs
It's probably the line endings. Try
^(?!a href).*\r\n
Each line of a text file stored in PC format ends with the two characters: carriage return, line feed (CR LF) (\r\n). WildEdit is somewhat unfriendly in the way it handles carriage returns. If '.' does not match a newline character is selected, then neither . (dot) nor \n matches a carriage return (\r).