I was wondering if anyone could assist please? Say I had data in the following format...
1 (id)
xxx
2
3
rrr
4
2 (id)
aaa
1
3
zzz
6
3 (id)
xxx
2
3
rrr
4
I would like to insert a "+" symbol in front of the id field [see the fields marked with (id)]. The data should look like this...
+1
xxx
2
3
rrr
4
+2
aaa
1
3
zzz
6
+3
xxx
2
3
rrr
4
As you can see from the above example, I would simply create a macro and insert a "+" at the beginning of every 7th line. No problems doing that with a macro. I use different text files that have different amounts of data. In the example above, it was every 7th line, the next file maybe every 100th line and so on. Is it possible to eneter a parameter that reflects the nth number of lines I'd like to insert a "+" symbol?
TEXTPAD DATA INSERTION EVERY nTH LINE
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
You can't provide parameters to TextPad macros or regexes.
For a fixed repeat interval, you can do something like this:
This assumes you are using Posix regular expression syntax:
((.*)\n){6}
because the regex engine used by TextPad doesn't support nested newlines. WildEdit (http://www.textpad.com/products/wildedit/) might be of help here.
Alternatively, write a script in a suitable language.
For a fixed repeat interval, you can do something like this:
but that quickly gets tedious and, anyway, TextPad only allows nine tagged subexpressions, so it can't cope with an repeat interval greater than 9.Find what: (.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n
Replace with: \+\1\n\2\n\3\n\4\n\5\n\6\n
[X] Regular expression
This assumes you are using Posix regular expression syntax:
Unfortunately you can't search forConfiguration | Preferences | Editor
[X] Use POSIX regular expression syntax
((.*)\n){6}
because the regex engine used by TextPad doesn't support nested newlines. WildEdit (http://www.textpad.com/products/wildedit/) might be of help here.
Alternatively, write a script in a suitable language.
TEXTPAD DATA INSERTION EVERY nTH LINE
Appreciate the assistance. Many thanks for your kind support. Even though the solution isn't solved entirely, it's telling me a bit more about what TextPad can and can't handle.
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
I looked at the content vs. the line counting and this works for me:
Search for: ^(.*)\(id\)\n
Replcae with: +\1\n
Search for syntax explanation:
^ = from start of the line
(.*) = any group of characters (element 1 = \1)
\(id\) = followed by (id) ---- (using \( and \) for paranthesis chars)
\n = at the end of the line
Replace with syntax explanation:
+ = plus character
\1 = element 1 contents (see above, characters in front of (id) )
\n = end of line
Search for: ^(.*)\(id\)\n
Replcae with: +\1\n
Search for syntax explanation:
^ = from start of the line
(.*) = any group of characters (element 1 = \1)
\(id\) = followed by (id) ---- (using \( and \) for paranthesis chars)
\n = at the end of the line
Replace with syntax explanation:
+ = plus character
\1 = element 1 contents (see above, characters in front of (id) )
\n = end of line
Hope this was helpful.............good luck,
Bob
Bob