Skip to main content

Hi Experts,

I have a text file and I want to extract the below information from it. PFA the text file.

At first, I want to extract the unique code 100101(which is for section 1001 (second line)), the name for that code (might not be unique) and the Lat/Long (Y,X coordinates). I want to save the output in a text file with one space/comma (delimiter).

Is it possible with FME? From my side, I tried using Text file reader with substring extractor yet I am not getting what I exactly want to do.

Hi @dewan, the StringSearcher can be used to extract required parts from a text line. This regex could help you if I understood the requirement correctly.

^\s*(\d+).+Pl\.:\s*(c^,]+).+Y=\s*(\d+\.\d+)\s*X=\s*(\d+\.\d+)

The transformer stores the parts that match the sub expression surrounded by brackets into a list attribute. Then, you can concatenate elements of the list with the ListConcatenator.


Hi @dewan, the StringSearcher can be used to extract required parts from a text line. This regex could help you if I understood the requirement correctly.

^\s*(\d+).+Pl\.:\s*(c^,]+).+Y=\s*(\d+\.\d+)\s*X=\s*(\d+\.\d+)

The transformer stores the parts that match the sub expression surrounded by brackets into a list attribute. Then, you can concatenate elements of the list with the ListConcatenator.

Hi @takashi. It works perfect. Just perfect. But I am not good at Regular Expressions and neither would I be able to learn it in a day or two and I really need to work on a lot of data. Are there any other methods to do that? So that I could apply the same logic for every file. Thanks for the quick response.


Hi @takashi. It works perfect. Just perfect. But I am not good at Regular Expressions and neither would I be able to learn it in a day or two and I really need to work on a lot of data. Are there any other methods to do that? So that I could apply the same logic for every file. Thanks for the quick response.

@dewan, if widths of required columns are fixed, the CAT (Column Aligned Text) reader may be helpful to read the source text file. You can set the column widths as the reader parameter when you add the CAT reader.


@dewan, if widths of required columns are fixed, the CAT (Column Aligned Text) reader may be helpful to read the source text file. You can set the column widths as the reader parameter when you add the CAT reader.

This old post on the blog about the CAT reader may be of help. The X and Y columns appear to line up in your data so I would certainly start with this format.

http://blog.safe.com/2011/11/fmeevangelist90/


Reply