Search code examples
regexetlapache-nifiremoving-whitespace

Is it possible to remove white spaces from the CSV files header name in NiFi?


I have a CSV file in which some column name have white spaces in it and some column names are without the white space between characters. I want to remove the white spaces from all the header names that has white space in it. Please help. Thank you!

Attaching screenshot for reference. Example: 'First Name' I want 'FirstName'

I am using ReplaceText processor in which under Search value I have passes \s to search just the header row white spaces and replacement value as Empty string. Also my evaluation mode is 'Line-by-Line'. so now the ouput file is showing as FirstName,LastNameshraddha,srivastavsanstuti,srivastav So it's showing everything in one line. I want white spaces only to be removed from header row and do not touch/merge the data values at all.Thanks

Please tell me how to remove them. Thank you!

enter image description here


Solution

  • @Shu is on the right direction, but the problem is that all spaces in the text will be replaced. In order to replace spaces ONLY in header row, in Shu's solution change:

    1. Search Value:

    (?s)(^[^\n]*)(.*$)

    1. Replacement Value:

    ${'$1':replace(" ","")}$2