Delete specific lines from file
Moderators: AmigoJack, bbadmin, helios, MudGuard
-
F. Tin-Loi
- Posts: 2
- Joined: Tue Aug 26, 2003 5:04 am
Delete specific lines from file
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
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
- talleyrand
- Posts: 624
- Joined: Mon Jul 21, 2003 6:56 pm
- Location: Kansas City, MO, USA
- Contact:
-
F. Tin-Loi
- Posts: 2
- Joined: Tue Aug 26, 2003 5:04 am
- talleyrand
- Posts: 624
- Joined: Mon Jul 21, 2003 6:56 pm
- Location: Kansas City, MO, USA
- Contact:
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
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
Bob
- MudGuard
- Posts: 1295
- Joined: Sun Mar 02, 2003 10:15 pm
- Location: Munich, Germany
- Contact:
- talleyrand
- Posts: 624
- Joined: Mon Jul 21, 2003 6:56 pm
- Location: Kansas City, MO, USA
- Contact:
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact: