Delete a variable amount of text between two words?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
scottatbhm
Posts: 12
Joined: Thu Mar 12, 2009 10:08 pm

Delete a variable amount of text between two words?

Post by scottatbhm »

I have to format about ten thousand lines of account information for an Excel import. I need to anywhere from one line of text to ten lines of text that occur in every account. There are unique phrases before and after the text I need to delete. Thanks for your help in advance.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You left out a word. Do you want to delete the lines of text?

You can't do this easily with regular expressions in TextPad. Textpad's regular expressions are incapable of matching an arbitrary number of lines.

But you can record a macro that
searches for the text that precedes the section to be deleted,
moves past that text,
searches for and extends the selection to the text that follows the section to be deleted,
moves the end of the selection back to the beginning of that text, and
deletes what is now selected.

You can then run this macro repeatedly over the entire document.
scottatbhm
Posts: 12
Joined: Thu Mar 12, 2009 10:08 pm

Post by scottatbhm »

Hi Ben, your assumption was correct...I meant to delete the lines of text. I know how to run the searches, but how do I select the text between and delete it? Thanks!!
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

When you perform a search you can choose Extend Selection, which causes the current selection to be extended to the end of the matching text.

You can move the end of the current selection by holding down the shift key while moving the cursor.

Does this clarify things?
scottatbhm
Posts: 12
Joined: Thu Mar 12, 2009 10:08 pm

Post by scottatbhm »

Ben, first - thank you for your time in responding to my problem. My goal is to search for a text string, search for another text string and then select and delete all data between the two text strings. I don't mind recording a macro, but because the data between the two text strings will vary in length, if I have to select with the mouse, I may as well delete it manually. Can textpad do this, or should I be using Perl? Thanks again.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

For your macro, here i s the basic flow:
Find string 1
Set a bookmark (CTL-F2)
Find string 2
Set a bookmark (CTL-F2)
Go to previous bookmark (SH-F2)
Go to (CTL-G)
Select Next Bookmark
Enter Check in box to extend selection
Press OK
Include bookmark2 line (SH-DOWN)
Press Delete

You may need to include/remove a SH-UP/DOWN to include/exclude the beginning and/or ending lines. This routine is deleting complete lines, not starting/ending on specific strings that are found, but in the lines that include the strings.

Write down the steps you are taking, use hot keys where possible. After written down, do the steps manually a few times on different lines to make sure results are consistent. When good, then record your macro. Remember you cannot edit macros.
Hope this was helpful.............good luck,
Bob
Post Reply