Page 1 of 1
Delete specific lines from file
Posted: Wed Dec 17, 2003 10:53 pm
by F. Tin-Loi
Hi:
I have a text file of some 50,000 lines (representing text data records). I want to (a) identify all lines that contain say "abcd" (this occurs only once per line), and (b) delete from the file every second line from the identified lines in (a). For example, let the file contain:
line 1 ... abcd ...
line 2 ... abcd ...
line 3 ... abcd ...
line 4 ...
line 5 ... abcd ...
line 6 ...
line 7 ... abcd ...
line 8 ...
I would like to delete lines 2 and 5 from the file.
Thanks
Posted: Wed Dec 17, 2003 11:22 pm
by talleyrand
F5 - search
Find What = abcd
Mark All
Edit
Cut Other
Bookmarked Lines
Posted: Wed Dec 17, 2003 11:30 pm
by F. Tin-Loi
Thanks.
But I think your solution deltes ALL lines containing "abcd", not every second line.
Francis
Posted: Thu Dec 18, 2003 3:16 am
by talleyrand
Doh! Sorry, I should have read more closely. Hmmm, I don't think that's possible. I could probably write you a Python script if you need it --- it'd be trivial.
Posted: Thu Dec 18, 2003 7:17 am
by Bob Hansen

How about this as an approach. A two phase process: A macro to modify the lines to be removed, and then just delete them.
Prep before running macro:
1. Go to beginning of document
2. Set up Search, Replace with following values:
a. Search for "abcd"
b. Replace with "~qqq~" (or some other unique value)
3. Leave Replace window open
Phase-1 macro - Modify every other instance of "abcd"
Run the following macro (Run macro through entire document):
1. Find Next
2. Find Next
3. Replace
Phase 2 - Delete lines that were modified.
1. Close Replace window.
2. Go to beginning of document
3. Search, Find "~qqq~"
4. Mark All
5. Edit, Delete, Bookmarked Lines
===============================
This is just an untested concept for an approach, actual keystrokes may be slightly different, but I think this is pretty close. Hope this is a sensible solution for you.
Posted: Thu Dec 18, 2003 11:47 am
by mo
If you can do:
Find Next
Find Next
Replace
you can do
Find Next
Find Next
Bookmark
on the original abcd
No?
Then Cut Other Bookmarked
Posted: Thu Dec 18, 2003 11:49 am
by MudGuard
Why the second phase?
Instead of modifying the line, simply delete it...
i.e.: Modify Phase 1 to:
Search for abcd
Find Next
Find Next
Edit - Delete - Line
Posted: Thu Dec 18, 2003 2:46 pm
by talleyrand
Well sure, if y'all want to take the
easy way out, you can do that...

Posted: Thu Dec 18, 2003 5:29 pm
by mo
Yeah, we can't have people going and actually thinking about things before they post! Gives the rest of us a bad rep.
Posted: Fri Dec 19, 2003 12:00 am
by Bob Hansen
I don't even recognize my first suggestion
Good work everyone!
F. Tin-Loi should be all set now!