Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Replace Text search with large file in NIFI

avatar

Hi,

Greetings!

I am using NIFI (1.2.0) & struggling with Replace text processor to bring record in a single line,as for now it split a record in 2 line.
Input record (record-1.png) has Description & filed Value, I want to bring value only in a single line which is replaced by pipe symbol (|). But it split record in 2 lines (split_record.png)
I am using following option for Replace Text ( replace-text.png)
46415-vle6q.pngrecord-1.png
replace-text.png

split-record.png

46414-apqew.png

1 ACCEPTED SOLUTION

avatar
Master Guru

@Rustam kapuria

I suspect in your input record having \n for one of the value, so when we do Replace Text processor the resultant content is writing into 2 line.

To resolve this issue you need to use escape json function in replace text processor.

Replacement Value

${ID_NO}|${CHANGE_TITLE:escapeJson()}

Same way as above you need to mention escape json function where you are having \n in json message.

Configs:-

45564-replacetext.png

Make sure which json value having \n in it and use escapeJson function for that attribute in Replace Text processor.

Refer below link for more details

https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#escapejson

Here is what i tried:-

Input record:-

{"ID_NO": "8.92" ,"TITLE": "HCC\n"}

Evaluate Json Path:-

Destination

flowfile-attribute

Return Type

auto-detect

Path Not Found Behavior

ignore

Null Value Representation

empty string

CHANGE_TITLE

$.TITLE

ID_NO

$.ID_NO

Output of Eval json path processor:-

45561-eval-json.png

Even though i'm having \n after HCC for CHANGE_TITLE,\n is not viewed in attributes tab but when we use CHANGE_TITLE in Replace Text processor it will replace the value with new line.

Replace text processor Configs without escapeJson Function:-

Search Value

(?s)(^.*$)

Replacement Value

${ID_NO}|${CHANGE_TITLE}

Maximum Buffer Size

10 MB

Replacement Strategy

Always Replace

Evaluation Mode

Entire text

Output of replace Text processor without escapejson function:-

45562-output.png

As you can see the new line is appeared after replace text processor.

Replace text processor Configs with escapeJson Function:-

Search Value

(?s)(^.*$)

Replacement Value

${ID_NO}|${CHANGE_TITLE:escapeJson()}

Maximum Buffer Size

10 MB

Replacement Strategy

Always Replace

Evaluation Mode

Entire text

Output of replace Text processor with escapejson function:-

45563-output.png

as you can see the output is in one line because we have used escapeJson function so the processor escaped the \n and replaced whole content into one line.

Try with escapejson function, if the issue is still not resolved let me know..!!

View solution in original post

4 REPLIES 4

avatar

@Shu: thanks for taking out time. I tired this option, unfortunately it did not work.

avatar

@Shu : All attributes are in single line. replacement-value.png

avatar
Master Guru

@Rustam kapuria

I suspect in your input record having \n for one of the value, so when we do Replace Text processor the resultant content is writing into 2 line.

To resolve this issue you need to use escape json function in replace text processor.

Replacement Value

${ID_NO}|${CHANGE_TITLE:escapeJson()}

Same way as above you need to mention escape json function where you are having \n in json message.

Configs:-

45564-replacetext.png

Make sure which json value having \n in it and use escapeJson function for that attribute in Replace Text processor.

Refer below link for more details

https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#escapejson

Here is what i tried:-

Input record:-

{"ID_NO": "8.92" ,"TITLE": "HCC\n"}

Evaluate Json Path:-

Destination

flowfile-attribute

Return Type

auto-detect

Path Not Found Behavior

ignore

Null Value Representation

empty string

CHANGE_TITLE

$.TITLE

ID_NO

$.ID_NO

Output of Eval json path processor:-

45561-eval-json.png

Even though i'm having \n after HCC for CHANGE_TITLE,\n is not viewed in attributes tab but when we use CHANGE_TITLE in Replace Text processor it will replace the value with new line.

Replace text processor Configs without escapeJson Function:-

Search Value

(?s)(^.*$)

Replacement Value

${ID_NO}|${CHANGE_TITLE}

Maximum Buffer Size

10 MB

Replacement Strategy

Always Replace

Evaluation Mode

Entire text

Output of replace Text processor without escapejson function:-

45562-output.png

As you can see the new line is appeared after replace text processor.

Replace text processor Configs with escapeJson Function:-

Search Value

(?s)(^.*$)

Replacement Value

${ID_NO}|${CHANGE_TITLE:escapeJson()}

Maximum Buffer Size

10 MB

Replacement Strategy

Always Replace

Evaluation Mode

Entire text

Output of replace Text processor with escapejson function:-

45563-output.png

as you can see the output is in one line because we have used escapeJson function so the processor escaped the \n and replaced whole content into one line.

Try with escapejson function, if the issue is still not resolved let me know..!!

avatar

@Shu : There was a culprit record ending up with new line. Thanks for assisting. escapeJson() is working perfect now. thanks.