Skip to main content
Solved

Updating Text File (.txt).


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 

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

4 replies

dustin
Influencer
Forum|alt.badge.img+31
  • Influencer
  • 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
  • April 25, 2022
dustin wrote:

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
  • 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

@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


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