Support Questions
Find answers, ask questions, and share your expertise

ReplaceText with nested trim()

New Contributor

4496-screen-shot-2016-05-24-at-35900-pm.jpg

I am trying to use a ReplaceText processor (https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.ReplaceText/) to try and parse a fixed format length file.

Because each 'field' of the file is setup to accommodate some expected maximum size, there are natural occasions where white space comes into place. For example, field #4 in the above screen shot is expected to be a max of 40 characters, but obviously could be shorter, causing the additional white space.

I tried using trim() from the expression language (https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#trim) as shown in the screen shot and as follows:

|$1|$2|$3|${$4:trim()}

Which produces the following error:

org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException: Invalid Expression: ${environment}|${client}|${programTheme}|$1|$2|$3|${$4:trim()}|$5|$6|$7|$8|$9|$10|$11|$12|$13|$14|$15|$16|$24 due to Unexpected token '4' at line 1, column 3. Query: ${$4:trim()}: 

I'm guessing that nested expressions aren't allowed?

Does anyone have a recommendation for a work around to this problem?

4 REPLIES 4

Expert Contributor

Hi,

Can you try using something like this:

${environment}|${client}|${programTheme}|$1|$2|$3|${4:trim()}|$5|$6|$7|$8|$9|$10|$11|$12|$13|$14|$15|$16|$24

Thanks,

Sujitha

New Contributor
ReplaceText[id=2a5b954c-2a0d-46e9-923c-dc1136b80e95] ReplaceText[id=2a5b954c-2a0d-46e9-923c-dc1136b80e95] failed to process session due to org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException: Invalid Expression: ${environment}|${client}|${programTheme}|$1|$2|$3|${4:trim()}|$5|$6|$7|$8|$9|$10|$11|$12|$13|$14|$15|$16|$24 due to Unexpected token '4' at line 1, column 2. Query: ${4:trim()}: 

Similar error to what I got when I tried something along these lines:

|$1|$2|$3|${$4:trim()}

Super Guru

this is a regex variable not a nifi variable

Explorer

Hi

 

Try using the below method to  trim spaces

 

|$1|$2|$3|${'$4':trim()}