Sachith Muhandiram
Sachith Muhandiram

Reputation: 2970

How to remove specific text from a value using apache nifi

I have a csv file and I need to remove somespecific text from a colum and replace another value for that.

My csv

date,name
20191106,sachith

To do it, I have used UpdateRecord processor with following configurations.

/date -> ${field:replaceAll(2019,1212)}

CSV-Reader CSV-Reader

CSV-Record-Writer enter image description here

My current configurations makes following csv as result.

date,name
"",sachith

Expected result

date,name
12121106,sachith

What am I missing here? I have used QueryRecord processor, but it didnt solve my issue either.

Upvotes: 1

Views: 1108

Answers (1)

Ian Neethling
Ian Neethling

Reputation: 83

I can't confirm exactly what you have done without your full UpdateRecord config, but your Reader and Writer are 100% correct. To achieve your expected result you need to update your UpdateRecord config to the following: enter image description here

I changed the Replacement Value Strategy to 'Record Path Value' and that allows me to populate the date field using the record path on the right hand side of the '/date' Dynamic property. More info on how to use Record Path here: https://nifi.apache.org/docs/nifi-docs/html/record-path-guide.html

An alternative solution, closer to your original config is:

enter image description here

The only thing you were missing was to refer to the field's value. More on that in the docs (if you click the Additional Details link) for UpdateRecord here: https://nifi.apache.org/docs/nifi-docs/components/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.9.0/org.apache.nifi.processors.standard.UpdateRecord/index.html

My mind jumped to Record Path a bit too fast, but both work!!

Please let me know if you encounter any further issues :)

Upvotes: 1

Related Questions