Skip to main content

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

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 


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.


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


@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


Reply