Question

Replace values in textfile with values extracted from the filename for multiple files


Hello,

I have several textfiles which have filenames such as this with varying numbers:

2017061_XXX_6183378N_568614E_20170708_001.asvp

Inside the files is a header which is crucial that it is not altered as well as two columns of data:

( SoundVelocity 1.0 0 201707081732 0.0 0.0 -1 0 0 KM_DEFAULT E 0205 )

0.458 1475.522

0.379 1475.532

0.354 1475.523

0.393 1475.525

I need to extract the 6183378 and 568614 from each file and its filename, these numbers varies for each file since they are Y and X coordinates. This task is simple and I have done that in another workflow which builds a list of files. However what I need for this workflow is that it replaces just the 0.0 0.0 in the header with the coordinate values from the filename, this needs to be done on multiple files without making any other changes on the file contents or its delimiters.

I have tried several ways which includes bringing the textfile in as CSV and try to rename the attribute with a list value to no success. I have tried importing as a CAT and use stringreplacer in combination with my previous workflow of extracting the values. However I have not succeeded in this, I have just been able to populate the entire column below 0.0 0.0 with the values.

I have attached one of the files as a .ZIP if someone wants to try to help me.

Regards,

 

Robin


2 replies

Userlevel 1
Badge +21

Have you tried reading as a text file? Then a string replacer to replace the values in the first line?

Depending on your data you may want to match something more specific than 0.0 0.0

Thanks Egomm,

That was quite silly, I tried a similar solution however I did miss that you were able to use text_line_data as an attribute in the stringreplacer.

I am not quite that experienced in FME with text files and reg expressions.

I tested the solution and it works perfectly, I did a fanout based on the fme_basename and it works on multiple files.

However since the files are manually created they can contain errors, therefore I did not use Stringsearcher, I used several other transformers that tests the file format, the length of the files by user input indexes and then a splitter based on underscore. This workspace needs to be adapted for several variants of files by user input variables.

Thanks again for this help, it is appreciated!

Reply