Skip to main content
jiglesias
Silver ⭐️
April 11, 2019
Solved

getDelimitedField when delimiter is a \

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.

MattWho
MattWhoAnswer
Titanium ⭐️⭐️⭐️
April 11, 2019

@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.


2 replies

MattWho
Titanium ⭐️⭐️⭐️
MattWhoAnswer
Titanium ⭐️⭐️⭐️
April 11, 2019

@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.


Translate
jiglesias
jiglesiasAuthor
Silver ⭐️
April 11, 2019

@Matt Clarke thank you, it works.

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

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

Translate