Replace column values using Apache NiFi

846 views Asked by At

I have a sample csv looks like this

ID,FNAME,PROBLEM_COL
1,sachith,
2,nalaka,
3,john,
4,adams,

Always PROBLEM_COL value is empty. I want to replace empty with null string.

For that I used UpdateRecord processor and CSVReader with Use String Fields From Headers
Custom value as /PROBLEM_COL and ${field.value:replaceFirst('','null')}

This runs without error/warning. But PROBLEM_COL is not replaced. I had referred this, but this does not solve my issue. My headers are in block-letters.

3

There are 3 answers

0
daggett On BEST ANSWER
0
YuriR On

try to change your regex to be something like

',$'

which means: comma followed by end of line

0
Dario Lurido On

With processor UpdateRecord you can use

replace( /PROBLEM_COL, '', 'null' )