Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace text with value of attribute in Nifi ReplaceText processor?

I want to replace some of the content of flowfile(based on rgex which I have) with the attribute value of attribute say var1 which is 123 (shown in image). I am doing this with Replace Text Processor in Nifi but the contents are not getting replaced instead the flow file is getting dropped.

image of Data Flow

like image 261
Umang Soni Avatar asked Dec 03 '22 19:12

Umang Soni


1 Answers

You can use the following flow as an example to achieve the regex replacement.

enter image description here

The individual processor configurations are below:

GenerateFlowFile: This generates a flow file with some content. In this case, the content is This is my content.

enter image description here

UpdateAttribute: This adds an attribute with key=var1 and value=123.

enter image description here

ReplaceText: This looks for matches of the regex and replaces with the value of attribute var1. So, This is my content will be transformed to This is my 123.

enter image description here

OriginalContent: This is to see the actual content before the replace. It uses a PutFile processor.

enter image description here

UpdatedContent: This is to see the updated content. It uses a PutFile processor.

enter image description here

Verification

After the flow has run one time, you can verify the contents by looking at the generated files.

$ cat original/5601958271012409 
This is my content

$ cat updated/5601958271012409 
This is my 123
like image 106
Jagrut Sharma Avatar answered May 02 '23 07:05

Jagrut Sharma