Skip to main content
brajeshreddy
Gold ⭐️
Jul 21, 2023 10:37 AM UTC
Question

How to replace/add some text for a matching patter in Nifi

Hi,

 

Is there any processor to add some text/characters to each line in the flowfile in Nifi. Replace text seems to be more complicated given that the partiton value keeps changing.

 

compute incremental stats mydb.mytable partition (date=2023-07-21);

compute incremental stats mydb.mytable partition (name=abc);

to

compute incremental stats mydb.mytable partition (date='2023-07-21');

compute incremental stats mydb.mytable partition (name='abc');

 

Note: date=2023-07-21 comes as a complete string from the sys.partitions.part_name table in hive. We will need to add '' to the date.

2 replies

joseomjr
Gold ⭐️⭐️
Sep 16, 2023 8:30 PM UTC

ReplaceText processor should work..

This RegEx search pattern should do the trick:

^(.*?)\(([^=]*)=([^\)]*)\);$

With this replacement value:

$1($2='$3')

Don't forget to set the evaluation mode to line-by-line...

Translate
joseomjr
Gold ⭐️⭐️
Sep 18, 2023 8:11 PM UTC

Forgot the ";" in the replacement value

 

$1($2='$3');

 

Translate