Structured text to table

Hi,

Apologies if answered already somewhere here, I've searched the forum and couldn't find it though...

I'm trying to transform a structured text file - not any well-known formats like json, xml etc., but well-structured:

level1 <name1>

        Level1_1 <name1_1>

               var1 set <value1>

               var2 set <value2>

        endlevel

        Level1_2 <name1_2>

               var1 set <value3>

               var2 set <value4>

        endlevel

        Leveln_m <namen_m>

               varx <valuey>

        endlevel

endlevel

How to transform it into table where the rows are grouped by Leveln, then Leveln_m  and columns are values respectively?

I'm not a programmer, although familiar with simple programming, so I'd appreciate help for not-so-stupid-but-not-a-coder ;-)

TiA

Marcin

Hello Marcin,

I'm not quite sure how your output table should look like. Can you provide the table to your text-example?

Thank you,
Ferry

Hey Ferry,

I would take something like:

or:

or CSV like this:

_________________________________

Level1,Level1_1,var1,value1;

Level1,Level1_1,var2,value2;

Level1,Level1_2,var1,value1;

Level1,Level1_2,var2,value2;

...

_________________________________

Thanx,

Marcin

 

There are at least two ways to tackle the problem, unfortunately none of them are trivial absent the JSON or XML format:

1) transform your structured text file such that it will look like JSON format so to finally be able to use JSON Path - this requires alot of text parsing nodes (String Manipulation) ;

2) walk through each line, as many times as you have levels and to extract the var-value pairs directly - here you'll need to come up with an algorithm to extract the parent level information from each line;

Geo,

Thanx, I was suspecting it wouldn't be easy :(

Although arduous, the second looks promising, I'll have to get my hands dirty, since there's no alternative...

Marcin

It might be a little to late for Marcin, but for the reference here is a workflow that does what you were looking for.

Best,
Ferry