Solved

Transforming a text file with a special format


Hi,

I'm downloading a bunch of text files from an FTP server and the contents of each file is stored in an attribute. The format of a text file is as follows :

Station1;2022-04-12;09:00;Var1;True;30.4;Var2;True;0.5;Var3;False;0.0;

Station2;2022-04-12;08:00;Var1;True;33.4;Var2;True;0.5;Var4;True;10.3;

Station3;2022-04-12;09:00;Var1;True;27.4;Var3;True;0.5;

 

What I would like to do is transform this text to a table as in the attached screenshot, but I have not found any easy way to do it in FME. Would you have any suggestions?

 

Thanks!

Screen Shot 2022-05-17 at 12.12.18 AM 

icon

Best answer by geomancer 17 May 2022, 16:58

View original

6 replies

Userlevel 4
Badge +25

If it's stored in an attribute you can use the AttributeSplitter, with the ; as a separator character, to break it up into a list.

Userlevel 6
Badge +32

This was a nice puzzle. Attached a sample workspace what does what you need.

Userlevel 4
Badge +36

A nice puzzle indeed! I took another approach, mostly consisting of moving data in and out of lists.

Station_list

Userlevel 1
Badge +10

I'd split the station name and time off first with some regex (assuming the Variable always starts with Var) and then split the remainder, first into groups of the 3 values and then by the semi colon

image

Userlevel 4
Badge +36

I'd split the station name and time off first with some regex (assuming the Variable always starts with Var) and then split the remainder, first into groups of the 3 values and then by the semi colon

image

Very compact, with much happening in every transformer. Great use of regex too!

Only I didn't like the assumption that the variable name always starts with Var, so I opted for a regex finding the third semicolon. I used a similar regex in the StringSearcher.

Station_list_ebygommCredits should go to @ebygomm​ here though!

Thank you for your answers, it works perfectly. These are some clever uses of regex!

Reply