Parent-child relationships

General questions about using TextPad

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

Post Reply
sine80
Posts: 3
Joined: Mon Mar 14, 2011 2:11 pm

Parent-child relationships

Post by sine80 »

Greetings!

I'm working on trying to determine how I can formulate an RE given parent child relationship from the file I'm working with. In sum, the file is formatted as follows:

Code: Select all

Master record     Field1     Field2     Field3     Field4     
                                                                              Parent     
                                                                                  Child 
                                                                                  Child  
                                                                                  Child
                                                                                  Child 
                                                                              Parent
                                                                                  Child
                                                                                  Child
                                                                              Parent
                                                                                  Child

One other note... The parent-child relationships are dollar values. The decimals points allign, the fields do not have a static startnig column. Example:

Code: Select all


        1,327.23   (parent)
         1,000.00   (child)
           100.00   (child)
            50.00   (child)
             5.00   (child)
           172.23   (child)

Thanks for any suggestions or assistance in advance!
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

What are you trying to do?

Show some example input as it is and as you would like it to be.
sine80
Posts: 3
Joined: Mon Mar 14, 2011 2:11 pm

Post by sine80 »

ben_josephs wrote:What are you trying to do?

Show some example input as it is and as you would like it to be.
I'd like to get everything in a single row. I'm unsure how to proceed after reformatting or joining the row and then keeping the parent child fields distuniguisable after removing all the blank spaces.

Current layout:

Code: Select all

111111111111 N NNN-NNNNNNNNN  99/99/99      6,666.66           3,333.33   77777777                                                M
      4              5.55        8,888.88       2,222.22        9,999.99   33333333 4444444444 55555555 66666666666666
                                                                9,999.99   33333333 4444444444 55555555 66666666666666
                                                                9,999.99   33333333 4444444444 55555555 66666666666666
                                                              33,333.33   88888888
                                                                  999.99   33333333 4444444444 55555555 66666666666666
                                                               99,999.99   33333333 4444444444 55555555 66666666666666
Desired:

Code: Select all

111111111111, N NNN-NNNNNNNNN, 99/99/99, 6,666.66, 4, 5.55, 8,888.88, 2,222.22, 3,333.33, 77777777, 9,999.99, 33333333, 4444444444, 55555555, 66666666666666, 9,999.99, 33333333, 4444444444, 55555555, 66666666666666, 9,999.99, 33333333, 4444444444, 55555555, 66666666666666, 33,333.33   88888888, 9,999.99, 33333333, 4444444444, 55555555, 66666666666666, 9,999.99, 33333333, 4444444444, 55555555, 66666666666666
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

There are some typos there and not everything is clear. But here, at least, is an approximate solution:

0. Use "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
1. Remove each newline preceding a line that begins with a space:

Search | Replace... (<F8>):
Find what: \n_ [Replace the underscore with a space]
Replace with: [nothing]

[X] Regular expression

Replace All
2. Replace each sequence of spaces with a comma and a space (this also puts a comma after the solitary N):

Search | Replace... (<F8>):
Find what: _+ [Replace the underscore with a space]
Replace with: ,_ [Replace the underscore with a space]

[X] Regular expression

Replace All
3. Reorder the fields:

Search | Replace... (<F8>):
Find what: ^(([^_]+,_){5})(([^_]+,_){2})[^_]+,_(([^_]+,_){4}) [Replace the underscores with spaces]
Replace with: \1\5\3

[X] Regular expression

Replace All
sine80
Posts: 3
Joined: Mon Mar 14, 2011 2:11 pm

Post by sine80 »

WOW, thanks for your help! I've searched around and this is light years from where I was after several attempts to tackle on my own.

Are you familiar with a topic that covers similar RE's for my own edification? I need to continue refining, but this is an awesome start.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

TextPad's help has something on regular expressions, although it's rather brief. Look under
Reference Information | Regular Expressions,
Reference Information | Replacement Expressions and
How to... | Find and Replace Text | Use Regular Expressions.

There are many regular expression tutorials on the web, and you will find recommendations for some of them if you search this forum.

A standard reference for regular expressions is

Friedl, Jeffrey E F
Mastering Regular Expressions, 3rd ed
O'Reilly, 2006
ISBN: 0-596-52812-4
http://regex.info/

But be aware that the regular expression recogniser used by TextPad is very weak compared with modern tools. So you may get frustrated if you discover a handy trick that works elsewhere but doesn't work in TextPad.
shippee
Posts: 12
Joined: Fri Dec 26, 2008 9:40 pm
Location: Olympia, Washington
Contact:

the regular expression recogniser used by TextPad is weak

Post by shippee »

ben_josephs stated:

But be aware that the regular expression recogniser used by TextPad is very weak compared with modern tools. So you may get frustrated if you discover a handy trick that works elsewhere but doesn't work in TextPad.

Is there another one recommended to supplement TextPads limitations perchance?

Thanks in advance,
Post Reply