cut and delete in a macro

General questions about using TextPad

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

Post Reply
Nico
Posts: 6
Joined: Thu Oct 02, 2003 2:49 pm

cut and delete in a macro

Post by Nico »

Hello I have a lot of records like this...

500 a
700 b
900 c
901 f
902 e

500 a
700 b
900 c
901 d
902 e


I want to make a macro that searches for records with
an 'f' on 901, and then deletes the record beginning with 500 til 902

It is difficult for me to let the cursor go up to 500 (from startpoint 901) and then blocks to 902 and to delete the complete record.

Something like (from 500) "shift and arrow down to 902"

Who can give me an solution for this problem.

Thanks in advance

With kind regards,
Nico

ps
sorry for the poor English.....
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

It sounds to me like you've already got it. If I understand properly you should do something like this:
=========================
CTL-Home //to go to start of document

Run this recorded macro:
F5 901 f //to find 901 f
CTL-ENTER //to select 901 f
Shift-Tab 2x, ENTER //to close Find window
UP 3x //to go to 500 a
Shift-DOWN 6x //to highlight all five lines plus blank line
Delete // to remove all five lines

When you save the macro, select it to repeat through to the end of the file

This should end up deleting all the blocks that have "901 f" in the middle.
Hope this was helpful.............good luck,
Bob
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

Find (Regex!)
.*\n.*\n.*\n901 f\n.*\n
Replace by nothing
Nico
Posts: 6
Joined: Thu Oct 02, 2003 2:49 pm

Post by Nico »

Thanks for your reactions.
I was not specific enough.
The records are not always exact with 5 lines,
sometimes there is a line with 904 p
I was looking for a solution that, when I let the cursor move to 500, a search starts for the next line 500 and
then everything between those '500s' blocks and deletes.

I was not able to get this working?
".*\n.*\n.*\n901 f\n.*\n "
and yes I had the regular exp on..

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

Post by talleyrand »

Check your regex style. I'm guessing that's Posix style.
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 »

I hate to drag this out, but can you provide a an example of the expression you mentioned here?
I was not specific enough.
The records are not always exact with 5 lines,
sometimes there is a line with 904 p
I was looking for a solution that, when I let the cursor move to 500, a search starts for the next line 500 and
then everything between those '500s' blocks and deletes.
Show some before and after examples in addition to the words. It will make it much easier to get you a sensible solution.
=======================================

Re the RegEx, I believe that the sample
.*\n.*\n.*\n901 f\n.*\n

does not have any unique POSIX terms, but it is trying to go across multiple lines which I don't think is supported in TextPad RegEx expressions.
==============================
Hope this was helpful.............good luck,
Bob
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

Bob, regexes work across multiple lines in Textpad
IF (and only if) the line breaks are given as \n.

You can't have \n in any partial expression that is repeated like
\n+
(.*\n)+
These won't work.

But if you search for a simple \n it works.

Nico, for some reason you have added a blank at the end of my expression. This will make the regex search fail because the empty lines do not have a blank in them...

But the Regex will not work for you anyway as you said the number of lines in a block is not constant, and as explained above, \n can't be used with a repeat operator in Textpad...
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

You are right mudguard :D

Arrrgh! I should have copied the original code from your posting. :oops:
But I had copied Nico's copy of the RegEx and it was not working for me either. The sample code I cut/paste from Nico's example also had trailing spaces at the end, before the \n. So I was getting no matches, that is why my comments abour the multiple lines. :oops: (At least I qualified by thoughts with "I think" and did not make it absolute).

Thanks for the clarification. I should have known better because I have used strings of \n before, but don't recall using .*\n, that was nice. So basic, embarassed I did not see it.

But your RegEx approach can still be used with the new "904 p" spec. Just need to add one more .*\n entry, like:
".*\n.*\n.*\n901 f\n.*\n". This will grab an extra blank line if no line with 904 p exists.

Thanks for the technique, into the toolbox it goes.
Hope this was helpful.............good luck,
Bob
Post Reply