Skip to main content

Hello,

 

I have what seems to be a simple task, but so far, have not been able to find the right solution.

 

I have an FME process that creates a CSV file with a header row, but it needs another "header" row above the actual header.

 

Below is an example of the CSV file with the header:

TagName,TimeStamp,FieldValue,DataQuality

LLSCADA.LL_EX02_BATTERY_VOLTS.F_CV,5/24/2021 12:45:00,6.37,Good

LLSCADA.LL_EX02_CHLORPHYL_UG_L.F_CV,5/24/2021 12:45:00,0,Good

 

The additional "header" row is simply the following:

>DATA]

 

Appreciate your time and any assistance,

 

Lowell

 

a possible solution would be to

  • use a FeatureWriter to store the CSV file
  • now read the CSV file with AttributeFileReader (read it in the same codepage as the CSV)
  • Concatenate [data] 'Carriage Return' with the attribute containing the CSV file
  • write as a text file with the extension .csv

I wouldn't recommend this for large CSV files, though.

 

Another way would be to:

  • use a FeatureWriter to store the CSV file
  • Prepare a Textfile writer with the extension .csv in the file name
  • Connect the Summary port of the FeatureWriter withn a AttributeCreator and create an attribute 'text_line_data' with the value 'DATA'
  • connect it with the Textfile writer
  • Connect the Summary port of the FeatureWriter with a FeatureReader
  • !!Set the Connection Runtime Order' by right-clicking on the connection and make sure that the flow to the Creation of the 'text_line_data' attribute goes first !!
  • Read the CSV file you created as a text file with a FeatureReader
  • Connect the output to the TextFile writer

Now, everything should be available in the right order

 

Possibly, there are easier ways to do this

 

 


a possible solution would be to

  • use a FeatureWriter to store the CSV file
  • now read the CSV file with AttributeFileReader (read it in the same codepage as the CSV)
  • Concatenate [data] 'Carriage Return' with the attribute containing the CSV file
  • write as a text file with the extension .csv

I wouldn't recommend this for large CSV files, though.

 

Another way would be to:

  • use a FeatureWriter to store the CSV file
  • Prepare a Textfile writer with the extension .csv in the file name
  • Connect the Summary port of the FeatureWriter withn a AttributeCreator and create an attribute 'text_line_data' with the value 'DATA'
  • connect it with the Textfile writer
  • Connect the Summary port of the FeatureWriter with a FeatureReader
  • !!Set the Connection Runtime Order' by right-clicking on the connection and make sure that the flow to the Creation of the 'text_line_data' attribute goes first !!
  • Read the CSV file you created as a text file with a FeatureReader
  • Connect the output to the TextFile writer

Now, everything should be available in the right order

 

Possibly, there are easier ways to do this

 

 

Hi jelle,

Thanks for the help. The file is small, 19 rows with 4 columns so I am trying to follow your 1st suggestion.

Not sure how to concatenate aDATA] with the attribute containing the CSV file.

I tried the following:FeatureWriterBut I did not do something quite right as the results look like this:

ResultsThanks again for your time and help.

Lowell


Hi jelle,

Thanks for the help. The file is small, 19 rows with 4 columns so I am trying to follow your 1st suggestion.

Not sure how to concatenate [data] with the attribute containing the CSV file.

I tried the following:FeatureWriterBut I did not do something quite right as the results look like this:

ResultsThanks again for your time and help.

Lowell

Hi Lowell,

 

I think it would be better to connect the AttributeFileReader to the Summary Port of the FeatureWriter. You do not need the text reader.

Concatenating the attribute goes as follows:

 

2021-05-26 19_18_52-_NONE → AUTOMATIONS (C__Users_Jelle_Documents_FME_Workspaces_backupSchedule.fmw) 

The FeatureWriter takes care of all the CSV settings. The reason not to pass all the records to the AttributeFileWriter is that you want to read it only once. With the StringConcatenator, you can add your additional line before the CSV as an attribute.

 

Good luck!


Hi jelle,

Thanks for the help. The file is small, 19 rows with 4 columns so I am trying to follow your 1st suggestion.

Not sure how to concatenate [data] with the attribute containing the CSV file.

I tried the following:FeatureWriterBut I did not do something quite right as the results look like this:

ResultsThanks again for your time and help.

Lowell

Sorry for continuing to be a bother. I have been able to get [data] in the text file, but the data is duplicated 18 times.

FeatureWriter_TextFileBelow is a sample of the output file. It has 18 sets of the same data. TextFileI've tried a number of other things, but either no data is written or [data] does not show in the output file.

 

Thanks - Lowell


Hi jelle,

Thanks for the help. The file is small, 19 rows with 4 columns so I am trying to follow your 1st suggestion.

Not sure how to concatenate [data] with the attribute containing the CSV file.

I tried the following:FeatureWriterBut I did not do something quite right as the results look like this:

ResultsThanks again for your time and help.

Lowell

Attached the AttributeFileReader to the Summary port of FeatureWriter, there should only be one feature come out of that. If not use a sampler to get just the last record.


Hi jelle,

Thanks for the help. The file is small, 19 rows with 4 columns so I am trying to follow your 1st suggestion.

Not sure how to concatenate [data] with the attribute containing the CSV file.

I tried the following:FeatureWriterBut I did not do something quite right as the results look like this:

ResultsThanks again for your time and help.

Lowell

Connecting it to the Summary port worked fine. Thank you!


Reply