You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by Thane Durey <td...@harding.edu> on 2020/11/23 18:41:41 UTC

ReplaceText with Variable Registry

How would I be able to use the a variable in the Search Value field for a ReplaceText processor?

My String
Some string has this "here, here" in it

What I want to Search
"here, here"

My Variable (must not include the double quotes for other reasons)
my.variable=here, here

I have a string I'm wanting to parse out of a large string. I thought the following would work:
Search Value: "${my.variable}"
Replacement Value: ["here", "here"]

I thought the above Search value would replace ${my.variable} with the string I've saved. So how could I used the variable registry in this Search Value?

Thanks

Re: ReplaceText with Variable Registry

Posted by Mark Payne <ma...@hotmail.com>.
Hello, Thane.

Yes, that should work fine. I did setup a simple flow to verify the behavior and it worked as I expected.

Perhaps you can provide a template of your flow? That may help to diagnose what’s going on.

Also, what version of NiFi are you running?

Thanks
-Mark


> On Nov 24, 2020, at 8:15 AM, Thane Durey <td...@harding.edu> wrote:
> 
> Does the variable registry allow for white space without single/double quotes?
> 
> I've spend the majority of yesterday and this morning still trying to figure out why this ReplaceText won't work with the variable registry.
> 
> Sadly, I can't find any online examples of how people have:
> 1. Used the variable registry in a ReplaceText -> Search Value field
> 2. How/If you can use white space within a variable, and what the syntax would be (if its ok to not include single/double quotes, or if you include a white space then you are required to add quotes of some kind).
> 
> 
> To provide some more context, my variable is being used as a tag system so I can tag my data with certain data types. So I have my variable registry file looking like this
> var1=somestring
> var2=anotherstring
> my.tag=linux, systemname
> my.tag2=windows, systemname
> my.tag3=linux, systemname1
> my.tag4=windows, systename1
> 
> After doing some minor processing on my data, I create a JSON using AttributesToJSON. Unfortunately, this doesn't set any fields to an Array. So I'm doing some "dirty" formatting and making the changes myself. My JSON looks something like this:
> {"somekey":"somevalue", "tags":"windows, systemname"}
> 
> This is where my ReplaceText comes into play. Before, I would do a literal string in my Search Value (in the ReplaceText) which would look like this: "windows, systemname"
> 
> This did exactly what I expected, but I wanted to try to get the variable registry to work as this will be easier for me to maintain. So I updated the Search Value field to look like this: "${my.tag2}"
> 
> Shouldn't this work? Or am I missing something? Any help would be appreciated.
> 
> On 2020/11/23 18:41:41, Thane Durey <td...@harding.edu> wrote: 
>> How would I be able to use the a variable in the Search Value field for a ReplaceText processor?
>> 
>> My String
>> Some string has this "here, here" in it
>> 
>> What I want to Search
>> "here, here"
>> 
>> My Variable (must not include the double quotes for other reasons)
>> my.variable=here, here
>> 
>> I have a string I'm wanting to parse out of a large string. I thought the following would work:
>> Search Value: "${my.variable}"
>> Replacement Value: ["here", "here"]
>> 
>> I thought the above Search value would replace ${my.variable} with the string I've saved. So how could I used the variable registry in this Search Value?
>> 
>> Thanks
>> 


Re: ReplaceText with Variable Registry

Posted by Thane Durey <td...@harding.edu>.
Does the variable registry allow for white space without single/double quotes?

I've spend the majority of yesterday and this morning still trying to figure out why this ReplaceText won't work with the variable registry.

Sadly, I can't find any online examples of how people have:
1. Used the variable registry in a ReplaceText -> Search Value field
2. How/If you can use white space within a variable, and what the syntax would be (if its ok to not include single/double quotes, or if you include a white space then you are required to add quotes of some kind).


To provide some more context, my variable is being used as a tag system so I can tag my data with certain data types. So I have my variable registry file looking like this
var1=somestring
var2=anotherstring
my.tag=linux, systemname
my.tag2=windows, systemname
my.tag3=linux, systemname1
my.tag4=windows, systename1

After doing some minor processing on my data, I create a JSON using AttributesToJSON. Unfortunately, this doesn't set any fields to an Array. So I'm doing some "dirty" formatting and making the changes myself. My JSON looks something like this:
{"somekey":"somevalue", "tags":"windows, systemname"}

This is where my ReplaceText comes into play. Before, I would do a literal string in my Search Value (in the ReplaceText) which would look like this: "windows, systemname"

This did exactly what I expected, but I wanted to try to get the variable registry to work as this will be easier for me to maintain. So I updated the Search Value field to look like this: "${my.tag2}"

Shouldn't this work? Or am I missing something? Any help would be appreciated.

On 2020/11/23 18:41:41, Thane Durey <td...@harding.edu> wrote: 
> How would I be able to use the a variable in the Search Value field for a ReplaceText processor?
> 
> My String
> Some string has this "here, here" in it
> 
> What I want to Search
> "here, here"
> 
> My Variable (must not include the double quotes for other reasons)
> my.variable=here, here
> 
> I have a string I'm wanting to parse out of a large string. I thought the following would work:
> Search Value: "${my.variable}"
> Replacement Value: ["here", "here"]
> 
> I thought the above Search value would replace ${my.variable} with the string I've saved. So how could I used the variable registry in this Search Value?
> 
> Thanks
>