Search code examples
csvapache-nifi

NiFi MergeContent to add a header with a new line in csv file


I am using MergeContent to merge csv contents. Finally I need to add a header to the csv file. Here is my configuration: enter image description here

As per suggestions to add new line https://community.cloudera.com/t5/Support-Questions/Adding-newline-when-using-mergecontent-processor-to-combine/td-p/240863 I am using Demarcator as ${literal('
'):unescapeXml()}

If I don't use Header, then my csv file is coming fine. But once I add the header then first line of csv file comes after the header without adding a new line. Now, after adding the demarcator I am observing that some of lines is missing and also first line is merged with header.

My output with above properties:

Name,City,First Name,Last NameJohn,New York,John, Kim

MaryAn,London,Mary,Hopkins

My output without Header and Demarcator: 5 lines of output as expected.

John,New York,John, Kim
MaryAn,London,Mary,Hopkins
Robin,Chicago,Rob,Barb
Donny,NewYork,Don,Singh
Rikki,London,Rikki,Patel

How to add new line after header and not miss my data


Solution

  • Since, I couldn't find solution for adding header in MergeContent. I used ReplaceText with below config:

    Search Value : (?s)(^.*$)
    Replacement Value : Name,City,First Name,Last Name
    Replacement Strategy: Prepend
    Evaluation Mode:Entire text
    Line-by-Line Evaluation Mode:All
    

    Remaining config values were default values