Â
Â
Is there a way for the reader to ignore these linebreaks?ÂÂ
Â
Is there a way for the reader to ignore these linebreaks?ÂÂ
Â
is your field value containing the line break surrounded by quotation marks?Â
Â
Example:Â
"the is aÂ
multi-line text"Â
It would help if you could post a sample record.Â
Â
DavidÂ
Â
Thank you for the quick replyÂ
Â
Yes, the value is surrounded by quotation marks. I don't see a way to attach a csv file here but the record looks something like this:Â
Â
"E","30-05-2007 22:00:00","16-07-2007 22:00:00","ACTIVE","BEMETERD","18062013XX259<crlf>Â
","18062013XX","SPZ REGIO 7 ZUIDWEST E"Â
Hi,
Â
Â
I does not seem like FME supports CSV files with newlines, even when they are quoted.Â
Â
Try to insert the following script into a PythonCreator, it uses the Python CSV module which supports newlines:Â
import fmeobjects
import csv
class FeatureCreator(object):
    def __init__(self):
        self.inputfilename = FME_MacroValues>'INPUT_CSV_FILE']
        self.csvdelimiter = ',' # Modify as needed
        self.csvquotechar = '"' # Modify as needed
        self.log = fmeobjects.FMELogFile()
        self.fieldnames = d]
       Â
    def close(self):
        with open(self.inputfilename, 'rb') as csvfile:
            csvreader = csv.reader(csvfile,Â
                                   delimiter=self.csvdelimiter,Â
                                   quotechar=self.csvquotechar)
            for n, row in enumerate(csvreader):
                if n == 0:
                    self.fieldnames = row
                    self.log.logMessageString("Attribute names to expose " + \
                        "in the PythonCreator:", fmeobjects.FME_WARN)
                    for field in row:
                        self.log.logMessageString("    "+field, fmeobjects.FME_WARN)
                else:
                    feature = fmeobjects.FMEFeature()
                    for m, value in enumerate(row):
                        feature.setAttribute(self.fieldnamesÂm], value)
                    self.pyoutput(feature)
Â
Notes: Hope this helps.
Â
Â
Davidfixcsvpython.fmw This little workspace will clean-up CSV files that have embedded linefeeds and then the CSV will process the data OK.
@MarkAtSafe - can you share that fmw files again. Seems to be coming up empty. Thanks!
@david_r : Thank you very much, this is a great solution!
@MarkAtSafe : It would be nice, if this could become an option for the default CSV-Reader and writer.
@david_r : Thank you very much, this is a great solution!
@MarkAtSafe : It would be nice, if this could become an option for the default CSV-Reader and writer.
Â
Add ability to read csv with linebreaksÂ
Â
Coming in 2017, see link aboveÂ
Hi @tino and everyone, take a look at the CSV2 Reader/Writer in the latest FME 2017.0 beta!
The workspace to pre-process your CSV to remove embedded linefeed / linebreaks is available in the KnowledgeBase article. Thanks @takashi for pointing out that this has been been addressed in FME 2017 beta releases in the updated CSV reader. To take advantage of the new reader in an existing workspace you need to add a new CSV reader and then remove or disable the original one.