Page 1 of 1
Replace a character every 999th row
Posted: Wed Feb 13, 2008 4:48 pm
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
Posted: Wed Feb 13, 2008 5:36 pm
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.
Posted: Wed Feb 13, 2008 6:16 pm
by DocX
Ok,
thanks for the information.
Bad for me, so I have to update all the rows manually.
Regards
Posted: Wed Feb 13, 2008 11:53 pm
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.
Posted: Thu Feb 14, 2008 9:27 am
by ben_josephs
I don't believe that one macro can call another one.
Posted: Thu Feb 14, 2008 3:18 pm
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 ...
Posted: Thu Feb 14, 2008 3:37 pm
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.