Skip to main content
Solved

Transforming a text file with a special format

  • May 17, 2022
  • 6 replies
  • 169 views

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

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!

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

redgeographics
Celebrity
Forum|alt.badge.img+59
  • Celebrity
  • 3699 replies
  • May 17, 2022

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
Forum|alt.badge.img+60
  • 2938 replies
  • May 17, 2022

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


geomancer
Evangelist
Forum|alt.badge.img+58
  • Evangelist
  • 932 replies
  • 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+44
  • Influencer
  • 3422 replies
  • 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+58
  • Evangelist
  • 932 replies
  • Best Answer
  • 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

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
  • 2 replies
  • May 18, 2022

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