Skip to main content

Hi,

Have multiple text files that need to be converted to a csv file.

The source text file contains three lines per object, which must be merged into 1 line. (number of objects is unknown in advance)

Example,

1

00:00:00,000 --> 00:00:01,000

F/6.3, SS 1000, ISO 100, EV -0.3, RTK (4.672639, 52.794202, 28), HOME (4.671729, 52.794208, 43.55m)

 

2

00:00:01,000 --> 00:00:02,000

F/6.3, SS 1000, ISO 100, EV -0.3, RTK (4.672639, 52.794203, 28), HOME (4.671729, 52.794208, 43.55m)

 

The result should be according to this example.

Time,F,S,Iso,Ev,RTK.Longitude,RTK.Latitude,GPS,Home.Longitude,Home.Latitude,Home.Elevation.m,

00:00:00.000,6.3,1000,100,-0.3,4.672639,52.794202,28,4.671729,52.794208,43.55

00:00:01.000,6.3,1000,100,-0.3,4.672639,52.794203,28,4.671729,52.794208,43.55

 

Who can help me with that, if only to merge 3 lines into 1 line in a loop.

Gerard

 

Grouping the lines can be done by using a Grouper custom transformer (by me, available in the FME Hub), then a ModuloCounter so we can process lines 2 and 3 per group separately (indexes 1 and 2 since the ModuloCounter starts counting at 0.

 

I use StringReplacers to format those lines, then aggregate them and contatenate the text_line_data attributes. Adding a separate header line and write out to CSV saves me the trouble of manually defining the output schema.

textline2textline.fmwt

Hope this helps!


One way to get a single line from the two lines (it doesn't look like the first line in your example is actually used?)

Expose the text_line_number on the text file, use an attribute creator with adjacent attribute handling. Use a conditional format to find every 2nd value in each group of 3, and join that value with the value of the following line of text. Only keep the records which have a value set

merge_text.fmwt


Hi! I think this is a good case for the ModuloCounter. Set it to three and exclude the first row, then merge the 2nd row with the 3rd (using the adjacent features in f.ex. AttributeManager). I've attached a workspace showing my thoughts / solution. Let me know if it matches what you need.

textfile_merger_modcount.fmwtcsv_data_fme.txt

Let me know if I got your question right, @gvenhorst


Hi,

Thanks for the examples, this solved my problem.

Gerard


Reply