"Counting" macros

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
stonescar
Posts: 3
Joined: Tue Oct 30, 2007 2:21 pm

"Counting" macros

Post by stonescar »

I was wondering if there was a way to use macros, and automaticly increase a value for each time its ran. For example:

ABCDEF 1
ABCDEF 2
ABCDEF 3
etc.

Is this posible?
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You can use TextPad's regexes for this.

For example, if you want 100 lines with the prefix "ABCDEF ", insert those 100 with just the prefix; then select all of them, and
Find what: $
Replace with: \i

[X] Regular expression

Replace All
The regex $ matches ends of lines; the replacement expression \i inserts incrementing sequence numbers.
stonescar
Posts: 3
Joined: Tue Oct 30, 2007 2:21 pm

Post by stonescar »

Thanks alot!

But what if i dont want the number on every line?
Like this:


XYZ
ABCDEF 1
QWERTY
XYZ
ABCDEF 2
QWERTY
XYZ
ABCDEF 3
QWERTY

etc.

Appreciate your help!
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Insert
XYZ
ABCDEF
QWERTY

as many times as required. Then something like
Find what: ^ABCDEF$
Replace with: \0 \i

[X] Regular expression

Replace All
stonescar
Posts: 3
Joined: Tue Oct 30, 2007 2:21 pm

Post by stonescar »

Ah! Thats excellent!
Thank you so much!
andy2509
Posts: 4
Joined: Mon Apr 30, 2007 4:39 pm

Post by andy2509 »

Hello,

I'm stuck at a similar point but have about 700 such unique combinations that need to be counted separately. Can someone please help me?

If it helps, I've got them sorted. Is there one single regex that I can run to maybe look at the previous line and compare the keys? The keys are always the first 17 characters of each line.

E.g.,
1234567890,ABC,XY,blah,blah,blah-a
1234567890,ABC,XY,blah,blah,blah-b
1234567809,ABD,XY,blah,blah,blah-a
1234567809,ABD,XY,blah,blah,blah-b
1234567809,ABD,XY,blah,blah,blah-c
1234567809,ABD,XY,blah,blah,blah-d

What I like to achieve:
1234567890,ABC,XY,0,blah,blah,blah-a
1234567890,ABC,XY,1,blah,blah,blah-b
1234567809,ABD,XY,0,blah,blah,blah-a
1234567809,ABD,XY,1,blah,blah,blah-b
1234567809,ABD,XY,2,blah,blah,blah-c
1234567809,ABD,XY,3,blah,blah,blah-d

If counts cannot start with 0, then I suppose I could handle that part later in Excel or something.

I apologize if this has been posted earlier. I searched but couldn't find any answers.

Thanks in advance,
Andy
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

In TextPad you can automatically insert sequence numbers, but you can't find a line only if it begins with the same text as the following or preceding line.

In WildEdit you can find each line that begins with the same text as the following line with something like
(([^,]*,){3}).*\r?\n(?=\1)
but you can't automatically insert sequence numbers.
andy2509
Posts: 4
Joined: Mon Apr 30, 2007 4:39 pm

Post by andy2509 »

Thanks for the quick response Ben! I'll see if I can use your regex somehow. Else, I'll have to build a small script to do it.

Anyway, appreciate your response and if anyone hasn't asked it yet, are you the God of regexs?!
Post Reply