Support Questions

Find answers, ask questions, and share your expertise

Nifi ReplaceText how can i change dot to comma

avatar
Explorer

I'm trying the processor ReplaceText to change all my dot to comma, but i can't

 

I really need some help here, please.

 

This is my CSV file:

 

MONEY (header)

109.29

 

I need this result

 

MONEY (header)

109,28

3 REPLIES 3

avatar
Master Mentor

@Acbx 

You should be able to easily do this based on your example easily with the ReplaceText processor configured as follows:

MattWho_0-1621545569148.png

If you found this addressed your query, please take a moment to login and click accept on the solution.
Thank you,

Matt



avatar
Explorer

Hi Matt

 

It doesn't work.

 

I dont know why but it has created 5 more columns

 

Acbx_0-1623075327303.png

 

avatar
Master Mentor

@Acbx 

It looks like your CSV uses commas as the field delimiter.  So the solution i provided parses the entire file line by line and changes all "." to ",".  So, I am guessing that you have other places within your CSV that also had ".", thus creating the additional 5 field columns.

Are trying to create a new column for cents?  Is that why you are changing 109.29 tp 109,29?
If you are not looking for a new column, how will downstream system parse this edited CSV now that you added a new comma in there?

You could write a complex Java regular expression in the Search Value to match only specifically on column number X (Money Column) and then use Replacement Strategy "Regex Replace" to edit it.

Let's assume the "Money" Column was column number 5. And then wrap money once converted from 109.29 to 109,29 in quotes so it is not treated as two columns later on....

Search Value:

^(.*?),(.*?),(.*?),(.*?),(.*?),(.*?)$

Replacement Value: 

$1,$2,$3,$4,"${'$5':replace(".",",")}",$6

MattWho_0-1623079977531.png

 

So above would manipulate column 5 only and change 109.29 in to "109,29".

Hope this helps you,

Matt