Skip to main content
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 

Best answer by geomancer

ebygomm wrote:

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!

View original
Did this help you find an answer to your question?

6 replies

redgeographics
Celebrity
Forum|alt.badge.img+48

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.


nielsgerrits
VIP

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


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • May 17, 2022

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

Station_list


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • May 17, 2022

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


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • Best Answer
  • May 17, 2022
ebygomm wrote:

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!


  • Author
  • May 18, 2022

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings