Page 1 of 1

"Counting" macros

Posted: Wed Oct 31, 2007 7:19 am
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?

Posted: Wed Oct 31, 2007 8:28 am
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.

Posted: Wed Oct 31, 2007 12:03 pm
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!

Posted: Wed Oct 31, 2007 12:46 pm
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

Posted: Wed Oct 31, 2007 2:17 pm
by stonescar
Ah! Thats excellent!
Thank you so much!

Posted: Fri Jan 16, 2009 6:01 am
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

Posted: Fri Jan 16, 2009 10:49 am
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.

Posted: Fri Jan 16, 2009 2:15 pm
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?!