TEXTPAD DATA INSERTION EVERY nTH LINE

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Paul Moon
Posts: 9
Joined: Wed May 17, 2006 3:38 am
Location: Melbourne, Victoria, Australia

TEXTPAD DATA INSERTION EVERY nTH LINE

Post by Paul Moon »

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?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You can't provide parameters to TextPad macros or regexes.

For a fixed repeat interval, you can do something like this:
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
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.

This assumes you are using Posix regular expression syntax:
Configuration | Preferences | Editor

[X] Use POSIX regular expression syntax
Unfortunately you can't search for
((.*)\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.
Paul Moon
Posts: 9
Joined: Wed May 17, 2006 3:38 am
Location: Melbourne, Victoria, Australia

TEXTPAD DATA INSERTION EVERY nTH LINE

Post by Paul Moon »

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.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

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
Hope this was helpful.............good luck,
Bob
Post Reply