Replace a character every 999th row

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
DocX
Posts: 2
Joined: Wed Feb 13, 2008 4:34 pm

Replace a character every 999th row

Post by DocX »

Hi Everybody,

I have a large textfile with a lot of rows. Each row contains one number and comma.

What I have to do now is that I have to replace the comma every 999th row with a String (e.g. test).

Is there a possibilty to do this automatically or do I have to do it manually?

Regards
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You can't do this in TextPad with regular expressions because of weaknesses in its regular expression engine. (You can't put a \n inside a repetition, and the regular expression appears to be restricted to 1023 characters, so that you can't have more than 255 repetitions of .*\n in it.)

Recording a macro to do it would be tedious in the extreme. You can solve part of the problem by recording a macro that moves down a line, and using Macros | Multi-play... to repeat it 999 times, but this doesn't really help very much.

This is another case that demonstrates the need for upgrading the regex engine or providing a scripting capability, or, preferably, both.
DocX
Posts: 2
Joined: Wed Feb 13, 2008 4:34 pm

Post by DocX »

Ok,

thanks for the information.

Bad for me, so I have to update all the rows manually. :-(

Regards
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

I think a macro combination could combine the movement and the replacement by using two macros.

Macro1 - Set to run 999 times.
Go to position at beginning of the line.
Press Down key

Macro2 - Set to run once.
Call Macro1
Search/Replace the comma.
Go to position to run macro1 again.

Repeat running Macro2 as many times as needed to process all lines.

=========================
I have not tried this, but I seem to recall that you can run a macro that calls another one. If not, then this will not work.
Hope this was helpful.............good luck,
Bob
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

I don't believe that one macro can call another one.
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

ben_josephs wrote:I don't believe that one macro can call another one.
What you believe is

- irrelevant ;-)
- in this case wrong


The problem I see is that "Multiplay" is disabled during macro recording, so it's impossible to create a macro that runs Bob's Macro1 999 times and then runs Bob's Macro2 ...

And a macro does only offer "Once", "Repeat thru Selection" and "Repeat to end of file" as storable repeat counters, not a fixed number ...
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

MudGuard wrote:What you believe is

- irrelevant ;-)
- in this case wrong
You're right on both counts. :-) Apologies for the false information!

I should avoid making statements about TextPad's macros because, as is plain, I'm not an expert on them. I rarely use them as (1) they're so weak and (2) you can't edit them.
Post Reply