Is it possible to remove white spaces from the CSV files header name in NiFi?

一曲冷凌霜 提交于 2019-12-05 08:26:21
Ed Ber

@Shu is on the right direction, but the problem is that all spaces in the text will be replaced. In order to replace spaces ONLY in header row, in Shu's solution change:

  1. Search Value:

(?s)(^[^\n]*)(.*$)

  1. Replacement Value:

${'$1':replace(" ","")}$2

Try with below ReplaceText configs:

Search Value

(.*)

Replacement Value

${'$1':replace(" ","")} //we are applying NiFi expression language replace function on the captured group.

Character Set

UTF-8

Maximum Buffer Size

1 MB

Replacement Strategy

Regex Replace

Evaluation Mode

Entire text //works with Line-By-Line mode also

Refer to this link for more details regards to NiFi expression language.

Input flowfile:

First Name,Last Name
shraddha,srivastav
sanstuti,srivastav

Output flowfile:

FirstName,LastName
shraddha,srivastav
sanstuti,srivastav

You should be able to do the following match:

/[\s]/g

It matches all white Space. Then simply replace with an empty string. Edit:

Try this instead:

/(?<!\n.+)[ ]/g

It will match a Space only if there's no Newline before it. In other Words, only the first line will match. Again, replace with an empty string.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!