Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

ReplaceTextWithMapping to replace value with space

Solved Go to solution

ReplaceTextWithMapping to replace value with space

New Contributor

Hi,

 

I try to replace text with space using ReplaceTextWithMapping processor. I have file with multiple lines

 

"action":"account sing up"
"action":"account sign in"
"action":"account sign out"

 

And I have a mapping file with \t separating the search value and replace value

 

 

account sing up    asu
account sign in     asi
account sign out    aso

 

 

Regular expressions "action":"(.*)"

Matching group: 1

 

Result

 

"action":"account sing up"
"action":"account sign in"
"action":"account sign out"

 

Expected:

 

"action":"asu"
"action":"asi"
"action":"aso"

 

 

Does anyone know what I did wrong?

 

Thanks

David

1 ACCEPTED SOLUTION

Accepted Solutions

Re: ReplaceTextWithMapping to replace value with space

Master Guru

Hello David,

 

The ReplaceTextWithMapping processor has been around for some time now and its design is rather simplistic in its current implementation. It is designed to match a simple regex that will map one group of non-whitespace characters to another group of characters (can have white space and back references).

 

in your example you are matching on a a set of characters that contains whitespaces.

 

If you were to add a replaceText processor to your flow to replace all the whitespace with a non-whitespace character like "-", then it will work. sample ReplaceText processor configuration:

Screen Shot 2019-10-09 at 1.42.06 PM.png
Your mapping file would of course then be based off this change:

account-sing-up	asu
account-sign-in	asi
account-sign-out	aso

 

the resulting mapping would then work:

Screen Shot 2019-10-09 at 1.46.24 PM.png

 

Thank you,

Matt

 

2 REPLIES 2

Re: ReplaceTextWithMapping to replace value with space

Master Guru

Hello David,

 

The ReplaceTextWithMapping processor has been around for some time now and its design is rather simplistic in its current implementation. It is designed to match a simple regex that will map one group of non-whitespace characters to another group of characters (can have white space and back references).

 

in your example you are matching on a a set of characters that contains whitespaces.

 

If you were to add a replaceText processor to your flow to replace all the whitespace with a non-whitespace character like "-", then it will work. sample ReplaceText processor configuration:

Screen Shot 2019-10-09 at 1.42.06 PM.png
Your mapping file would of course then be based off this change:

account-sing-up	asu
account-sign-in	asi
account-sign-out	aso

 

the resulting mapping would then work:

Screen Shot 2019-10-09 at 1.46.24 PM.png

 

Thank you,

Matt

 

Re: ReplaceTextWithMapping to replace value with space

New Contributor

Thank you. It really helps

Don't have an account?
Coming from Hortonworks? Activate your account here