Support Questions

Find answers, ask questions, and share your expertise

Replacing new lines, weird behavior observed

avatar
Expert Contributor

43536-line1.png

43537-lne2.png

Hi All,

Thanks a lot to this awesome community.

I am observing a new line is added in the beginning after replacing a text. but when observed through nifi ui I do not see the new line in the beginning.

I reffered this link

https://community.hortonworks.com/questions/147226/replacetextprocessor-remove-blank-lines.html

Any suggestion

Thanks Dheeru

1 ACCEPTED SOLUTION

avatar
Master Guru

@dhieru singh

Can you once check your replace text processor configurations

if the Replacement Strategy property as Prepend that means you are adding new line at starting of the file.

As that new line won't show in NiFi UI but when you do cat on the file then only it shows the new line.


op.png

View solution in original post

5 REPLIES 5

avatar
Master Guru

@dhieru singh

Can you once check your replace text processor configurations

if the Replacement Strategy property as Prepend that means you are adding new line at starting of the file.

As that new line won't show in NiFi UI but when you do cat on the file then only it shows the new line.


op.png

avatar
Expert Contributor

@Shu Thanks for the response I appreciate it. No I am not using Prepend strategy I am using regex replace all attached is the image

43540-regexreplace.png

avatar
Master Guru

@dhieru singh,

If your file having any new line as first line of your file that would won't show in NiFi UI.

you need to use another replace text processor following with the existing replace text processor

Search value property as

(\s$|^\s*)(.*) //match if you are having any new lines in starting and ending position of the file

Replacement value property as $2

42530-regex.png

Why existing replace text won't match empty lines?

As you are having replace text processor with

\n+\s //matches for only empty lines in between the text but not first

If you have empty lines in between the text then you are going to replace them with shift+enter.

But in this case you are having empty line at starting of the file then you need to take off them,that's the reason why you need to use another replace text processor.

Flow:-

First replace text processor //is going to replace empty lines in text with shift+enter.<br>second replace text processor //replace empty lines at first and end lines in text then remove them from file

avatar
Expert Contributor

@Shu thanks for the response will try and get back to you, appreciate it

avatar
Expert Contributor

@Shu I checked again, the regex \n+\s+ does not remove the first line if it is blank, other than that it replaces all the blank lines, even if there are empty lines in the end, trying your regex for removing first blank line Thanks again