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!

getDelimitedField when delimiter is a \

avatar
New Member

Hello,

I have an attribute log_source that holds a path like D:\dir1\dir2\dir3

I need to get only dir2 but I'm unable to escape the slash with ${log_source:getDelimitedField(3,'\')}

I've tried several things unsuccessfully.

1 ACCEPTED SOLUTION

avatar
Master Mentor

@Julian Iglesias

-

You can accomplish above using a function chain in your NiFi Expression Language (EL) statement.

Rather then using the getDelimitedField() EL function:

${log_source:getDelimitedField(3,'\')}

-
You can successfully do this using the substringAfter() function twice to strip away what is before "dir2" and the substringBefore() function to strip away everything after "dir2":

${log_source:substringAfter('\\'):substringAfter('\\'):substringBefore('\\')}

-

Thank you,

Matt

-

If you found this answer addressed your question, please take a moment to login in and click the "ACCEPT" link.


View solution in original post

2 REPLIES 2

avatar
Master Mentor

@Julian Iglesias

-

You can accomplish above using a function chain in your NiFi Expression Language (EL) statement.

Rather then using the getDelimitedField() EL function:

${log_source:getDelimitedField(3,'\')}

-
You can successfully do this using the substringAfter() function twice to strip away what is before "dir2" and the substringBefore() function to strip away everything after "dir2":

${log_source:substringAfter('\\'):substringAfter('\\'):substringBefore('\\')}

-

Thank you,

Matt

-

If you found this answer addressed your question, please take a moment to login in and click the "ACCEPT" link.


avatar
New Member

@Matt Clarke thank you, it works.

Just in case somebody needs it I managed to make it work using getDelimitedField

log_source:getDelimitedField(3, '\\', '"', '~')}