Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

How to apply replaceAll to ${path} on NiFi?

avatar
New Contributor

Hello!

 

I'm getting files from a SMB with GetSMBFile, eventually they'll be placed on S3 with PutS3Object, the problem is the path contains "\" on it and I need to replace all of those to "/", I attempted a simple ${path:replaceAll('\','//')}/${filename} on the Object Key but it didn't work.

 

What's the proper way to do this on NiFi?

1 ACCEPTED SOLUTION

avatar
Master Mentor

@MarcioMarchiori 

Depending on which NiFi Expression Language (NEL) function you are using, either of the following two NEL statements should work for you:

${path:replaceAll("\\\\",'/')}/${filename}

In above you are using the replaceAll function which expects a java regular expression.  Since '\" is an escape character and NiFi is a java application, the first \ escapes the second \ and the third \ escapes the forth \.   So \\\\ results in a regex of \\ being applied against the value present in the "path" variable.


or

${path:replace('\\','/')}/${filename}

In above you are using the replace function which does not path the first argument to be evaluated as a java regular expression but rather takes a string literal.  And since '\' is an escape character you need \\ which tells java to treat the second \ as the literal string value to search for.

If you found this response assisted with your query, please take a moment to login and click on "Accept as Solution" below this post.

Thank you,

Matt

View solution in original post

2 REPLIES 2

avatar
Master Mentor

@MarcioMarchiori 

Depending on which NiFi Expression Language (NEL) function you are using, either of the following two NEL statements should work for you:

${path:replaceAll("\\\\",'/')}/${filename}

In above you are using the replaceAll function which expects a java regular expression.  Since '\" is an escape character and NiFi is a java application, the first \ escapes the second \ and the third \ escapes the forth \.   So \\\\ results in a regex of \\ being applied against the value present in the "path" variable.


or

${path:replace('\\','/')}/${filename}

In above you are using the replace function which does not path the first argument to be evaluated as a java regular expression but rather takes a string literal.  And since '\' is an escape character you need \\ which tells java to treat the second \ as the literal string value to search for.

If you found this response assisted with your query, please take a moment to login and click on "Accept as Solution" below this post.

Thank you,

Matt

avatar
New Contributor

Thanks mate, I had completely forgotten about the need for the need for the '\\\\', that solved it.