Skip to main content
Solved

Updating Text File (.txt).

  • April 25, 2022
  • 4 replies
  • 165 views

Forum|alt.badge.img

I need to update a text file which contains the settings for an executable tool. It would be really useful if I could automate this in FME.

 

The text file is saved in UTF-8 format and for example, lines two and three contain the variables for START_TIME and END_TIME:

 

START_TIME=2005/01/01 00:00

END_TIME=2007/12/31 23:59

 

How can FME be used to change the two dates, 2005/01/01 and 2007/12/31?

 

Thank you, Rob

Best answer by dustin

FME reads lines of text as individual features using the Text Reader, and puts the text into an attribute 'text_line_data'. You could then filter the features by 'text_line_data BEGINS WITH START_TIME' AND 'text_line_data BEGINS WITH END_TIME' using a Tester or TestFilter.

I would probably setup two Text parameters in the workspace, one for START and one for END, for which you will enter the desired date/times. Using Regex Replacement in the StringReplacer, the date/time value would be replaced with what is input in the parameters. The resulting workspace would look something like the screen shot below. I don't know the Counter/Sorter is necessary, but it will ensure the lines of text are written in the same order.

 

image 

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.

4 replies

dustin
Influencer
Forum|alt.badge.img+31
  • Influencer
  • 627 replies
  • Best Answer
  • April 25, 2022

FME reads lines of text as individual features using the Text Reader, and puts the text into an attribute 'text_line_data'. You could then filter the features by 'text_line_data BEGINS WITH START_TIME' AND 'text_line_data BEGINS WITH END_TIME' using a Tester or TestFilter.

I would probably setup two Text parameters in the workspace, one for START and one for END, for which you will enter the desired date/times. Using Regex Replacement in the StringReplacer, the date/time value would be replaced with what is input in the parameters. The resulting workspace would look something like the screen shot below. I don't know the Counter/Sorter is necessary, but it will ensure the lines of text are written in the same order.

 

image 


Forum|alt.badge.img
  • Author
  • 14 replies
  • April 25, 2022

FME reads lines of text as individual features using the Text Reader, and puts the text into an attribute 'text_line_data'. You could then filter the features by 'text_line_data BEGINS WITH START_TIME' AND 'text_line_data BEGINS WITH END_TIME' using a Tester or TestFilter.

I would probably setup two Text parameters in the workspace, one for START and one for END, for which you will enter the desired date/times. Using Regex Replacement in the StringReplacer, the date/time value would be replaced with what is input in the parameters. The resulting workspace would look something like the screen shot below. I don't know the Counter/Sorter is necessary, but it will ensure the lines of text are written in the same order.

 

image 

What transformer would you recommend to filter the features by?

 

Just seen your update above.


dustin
Influencer
Forum|alt.badge.img+31
  • Influencer
  • 627 replies
  • April 25, 2022

I would use the TestFilter. @rob_nason​ You may have to expand the post to see the screenshot.


Forum|alt.badge.img+2
  • 1891 replies
  • April 26, 2022

@rob_nason​ Be careful with TestFilter - it might change the order of your records if you are using FME 2020 or higher:

imageSo either change that parameter to Preserve Feature Order: Across Ports (which might impact performance) OR...

Configure your Text File reader to read the entire file into a single attribute - and then use StringReplacer with a regex on that attribute.image