Page 1 of 1

Delete a variable amount of text between two words?

Posted: Thu Mar 12, 2009 10:14 pm
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.

Posted: Thu Mar 12, 2009 11:00 pm
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.

Posted: Fri Mar 13, 2009 11:28 pm
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!!

Posted: Sat Mar 14, 2009 8:55 pm
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?

Posted: Sat Mar 14, 2009 10:41 pm
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.

Posted: Sat Mar 14, 2009 11:00 pm
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.