Delete specific lines from file

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
F. Tin-Loi
Posts: 2
Joined: Tue Aug 26, 2003 5:04 am

Delete specific lines from file

Post 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
User avatar
talleyrand
Posts: 624
Joined: Mon Jul 21, 2003 6:56 pm
Location: Kansas City, MO, USA
Contact:

Post by talleyrand »

F5 - search
Find What = abcd
Mark All

Edit
Cut Other
Bookmarked Lines
I choose to fight with a sack of angry cats.
F. Tin-Loi
Posts: 2
Joined: Tue Aug 26, 2003 5:04 am

Post by F. Tin-Loi »

Thanks.

But I think your solution deltes ALL lines containing "abcd", not every second line.

Francis
User avatar
talleyrand
Posts: 624
Joined: Mon Jul 21, 2003 6:56 pm
Location: Kansas City, MO, USA
Contact:

Post 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.
I choose to fight with a sack of angry cats.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

:idea: 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.
Hope this was helpful.............good luck,
Bob
mo
Posts: 306
Joined: Tue Mar 11, 2003 1:40 am

Post 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
Last edited by mo on Thu Dec 18, 2003 11:49 am, edited 1 time in total.
Best Wishes!
Mike Olds
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post 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
User avatar
talleyrand
Posts: 624
Joined: Mon Jul 21, 2003 6:56 pm
Location: Kansas City, MO, USA
Contact:

Post by talleyrand »

Well sure, if y'all want to take the easy way out, you can do that... ;)
I choose to fight with a sack of angry cats.
mo
Posts: 306
Joined: Tue Mar 11, 2003 1:40 am

Post 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.
Best Wishes!
Mike Olds
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

I don't even recognize my first suggestion :cry:

Good work everyone! :D

F. Tin-Loi should be all set now!
Hope this was helpful.............good luck,
Bob
Post Reply