Page 1 of 1
New macro in textpad
Posted: Wed Mar 11, 2009 1:34 am
by wilder
Hello,
Newly with textpad, I need to create a macro that will back up a digit backward each too lines.
So if in line 2 - at position 27 on the line, you have le digits 1, it will backup the digits at position 26, but will leave the rest of the line at the same position.
After that, it will go to line 4, 6, 8, and will go on until there's no more data.
Is it possible and if so, how to do it?
Thanks for you help!
wilder
Posted: Wed Mar 11, 2009 2:03 am
by Bob Hansen
This can probably be done, but need more information.
Some questions come to mind, there could be more.....
Will the move always start on line 2?
Or how to locate the first instance? And then do every other line?
Do blank lines count as lines?
Will the digit always be in the same position, 27?
Will it always be a single digit?
Are there any other digits on the line.
Would be best to show real samples of about 10 lines that cover all possibilities. Show original lines before process, and show the modified lines after the process.
Posted: Wed Mar 11, 2009 9:47 am
by wilder
Every line starts with the letter H or D.
Now, for each line that starts with the letter D at position 1, we have to change the number that his in the position 27, end put it at the position 26.
Here is an example of the line that starts with D:
end
So the result should be for the 2 examples above:
and
So if you see at the example DM2, the number 1 as gone at position 26 but the number 8 on the same line stays at position 154.
Same for the DM61 with the digits 4, the number 855 and the number 8 stays at the same position but the number 4 went back to position 26.
Posted: Wed Mar 11, 2009 10:51 am
by ben_josephs
In these examples the numbers at the ends of the lines are at column 155 and are moved to column 154. I assume from your description that this is incorrect.
In your first message you said that this change should happen on every other line. In your second message you said that the change should happen on every line that begins with a
D. I assume the second description.
A macro is not required. If these assumptions are correct, this regular expression replacement should do it:
Find what: ^(D.{24}).([0-9]+)
Replace with: \1\2_ [Replace the underscore with a space]
[X] Regular expression
Replace All
This assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
Posted: Wed Mar 11, 2009 4:09 pm
by Bob Hansen
I am getting a different interpretation of the spec:
On lines starting with D
If there is a digit in position 27, move it to position 26, and leave all other chars in original position
============================
Find what: ^(D.{24}).([0-9])(.*)
Replace with: \1\2_\3
Use a space character for the _ in the replacement string.
Use the following settings:
-----------------------------------------
[X] Regular expression
Replace All
-----------------------------------------
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
-----------------------------------------
Posted: Wed Mar 11, 2009 8:57 pm
by ben_josephs
Hi Bob
The trailing (.*) in your regex and the corresponding \3 in the replacement are redundant. So your suggestion is equivalent to
Find what: ^(D.{24}).([0-9])
Replace with: \1\2_ [Replace the underscore with a space]
which is the same as mine except that it moves just one digit instead of a sequence of digits.
I agree that the spec is unclear. But the poster's first message refers to "the digits [plural] at position 26" and the second message refers to "the number [which I take to comprise possibly more than one digit] that his [sic] in the position 27".
Perhaps the poster might clarify.
Posted: Wed Mar 11, 2009 10:48 pm
by wilder
My second post was more precise and with example.
I'll try to edit the macro.
Is it possible to edit a macro in textpad?
Posted: Thu Mar 12, 2009 12:40 am
by Bob Hansen
Thanks for pointing out the redundancy, ben.
For wilder: As ben noted, no macro is needed. If you have any success editing your macro, let us know. For years it has been the most frequently requested enhancement. Unfortunately, TextPad macros cannot be edited.
Still not clear about how many numbers/digits might be at position 27. If more than one, would they all be moved back one position to start at position 26? Of are we only concerned with position 27, always a single digit?
Looking more closely at the spec, we both missed that lines that begin with D or with H would be done. So the Search string should be modified like this:
^([D|H].{24}).([0-9]+)
Posted: Thu Mar 12, 2009 1:15 am
by wilder
Sorry,
Yes, it's only one digit / number in position 27.
Posted: Thu Mar 12, 2009 2:08 am
by Bob Hansen
Then I think this is the answer for you:
Find what: ^([D|H].{24}).([0-9])
Replace with: \1\2_
In the Replace string, use a space char for _
Use the following settings:
-----------------------------------------
[X] Regular expression
Replace All
-----------------------------------------
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
-----------------------------------------
Posted: Thu Mar 12, 2009 9:01 am
by wilder
Thanks to everybody,
It work perfectly.
Posted: Thu Mar 12, 2009 9:19 am
by ben_josephs
In fact you wrote
for each line that starts with the letter D at position 1...
If you mean just those lines that begin with a D, use
^(D.{24}).([0-9])
If you mean lines that begin with either a D or an H, use
^([DH].{24}).([0-9])
(without the vertical bar).
Note that the terms digit and number are not interchangeable. A digit is a single character (0, 1, 2, ...). A number may be many characters (3, 42, 2.718281828, ...).