reduce the spaces between two columns

Hi Team,

The space between all the below columns is 10. but I want to reduce the space between first and second alone to 4.

current space:

Expected output

This is a bit high priority. quick response is appreciated.

Subramanyam Kinthada

@Subramanyam you could use the Column Expression

replace(column("Column1"), " "," ")

Also you could use RegEx to do that

strip(regexReplace(column("Column1"),"\\s{10,}" ," "))


Hi @mlauber71

Good Day,

unfortunately the above given function didn’t helped me.

how can we give the empty spaces between the columns.
For Example I want to give 4 empty spaces between the first and second column, 10 empty spaces between second and third column.

current output consists of same empty spaces between all the columns.

Please let me know if my query is understandable.

Subramanyam Kinthada.

Hi Team,

Can someone help me in resolving the issue.

Subramanyam Kinthada

Hi @Subramanyam , how are you reading the file? I mean, what’s the delimiter for the columns? Or is it just 1 column for the whole row?

And also, can you share the file so we can have an idea of what you are talking about and so we can have some data to test our solutions?

Also, please be advised that it’s a community forum, meaning that people will help when they can, and it’s usually slower over the weekend.

What exactly have you tried from @mlauber71 suggestions that you said did not work? Did you try his workflow? It looks like the forum might not display properly the expression - as you can see, the replace statement in the screenshot has the proper spaces, but the one pasted in the forum only have 1 space from search and replace. If you copied from the forum, then it’s normal that you did not replace anything, since it search for 1 space and replaced with 1 space.

The Regex solution that he suggested is also a valid alternative. Did you try it?

Hi @bruno29a,

Good Day,

Yes it is only one row in the table and we are extracting it out using the CSV writer node. now we require the empty spaces between the columns should be customized.

The empty space between first and second should be 4 and between second and third columns should be 11 and so on.

we have tried the formula provided by mlauber for each column but we didn’t received the output as expected.

Subramanyam Kinthada

Hi @Subramanyam sorry, but you have not answered any of my questions, and I still do not understand your data.

I asked if you were reading the whole line as 1 column or not, or at least if you could tell me what the delimiter was.

If you did not understand what I was asking, that is why I asked if you could share the file.

I am pretty sure I can help you, but I just don’t know how your data is being presented in Knime - basically I have no starting point. Can you at least show me how the data is shown in Knime?

With regards to your latest screenshot, I’m not sure what you are trying to do there. The expression that you are using says to replace 1 space with 4 spaces, meaning replace any spaces that you have x4 (1 space will become 4 spaces, 2 spaces will become 8 spaces since each of the 2 spaces will be replaced by 4 spaces each, 3 spaces will become 12 spaces, 4 spaces will become 16 spaces, etc). Is this what you want?

1 Like

@Subramanyam hoping not to undercut any efforts by the great @bruno29a :slight_smile: I have tried to put something together just for the fun of it. Not really sure this would make sense in a real world business task. But alas it can be done. Replace any number of blanks with a fixed number per column and bring them back together.

I might have gotten carried away somewhat - so if someone comes up with a better solution or it turns out this is not what is needed … so be it …

This is what the results would look like in the text editor …

kn_forum_45697_change_blanks_flexible_number_per_column.knwf (93.1 KB)


Hi @bruno29a

Good Day,

  1. The input file is a PDF and we have extracted the data from it using PDF Parser node.
  2. Later we transformed the data using Cell splitter nodes, String Manipulation nodes and cross joiners.
  3. There will be only one row as output and 9 columns as shown below.

KNIME Output:

  1. Using CSV Writer node we exported to local as .txt file but didnt achieved the expected output because of the empty spaces. We are using empty spaces as delimiters.

Current output having same number of spaces between all columns.

Expected output requires different number of empty spaces:

  1. We have applied the function to each column as suggested by Mlauber using Column expression node but the output is not occurred.

  2. Final requirement is I wanna make customized number of empty spaces between the columns.


Hi @mlauber71

Yes, We wanna apply the same to our data to get the expected output.
We have tried the replace function but unable to get the expected output.
replace(column(“first”)," “,” ") function we used.

Subramanyam Kinthada.

1 Like

Hi @Subramanyam , thank you so much for the additional info, now we’re getting somewhere.

So basically, I’ve come up with this method:

The idea is to set the delimiters between each column to 10 spaces, except between the first and second columns. Therefore, I first manually join the first and second columns with 4 spaces between them, making them become 1 column, and then join it as a column with the rest with 10 spaces between each.


This gives me this result:

As you can see, I have 4 spaces between 0 and 000000000, and the rest of them have 10 spaces between them.

Here’s the workflow: reduce spaces between two columns.knwf (13.9 KB)

EDIT: Here’s the file opened via Textpad so I can display the number of spaces:


Hi @bruno29a

Thanks for the above method. but my requirement is not the constant empty spaces between all the columns

first and second column ----4 spaces
second and third ------10 spaces
third and fourth ------ 4 spaces
fourth and fifth ------ 12 spaces
fifth and sixth ------ 5 spaces
sixth and seventh ----- 11 spaces
eight and ninth ----- 11 spaces
ninth and tenth ----- 117 spaces

So please kindly suggest the method to achieve the above requirement.

Thanks in advance.

Subramanyam Kinthada.

If you would take a look you would find that with my suggested approach you could just configure how many spaces you want to have between the individual columns. Maybe you give it a try :slight_smile:

Hi @bruno29a

Thanks a lot for the support.

I have achieved 90% of the output. I am able to join the last column with 117 empty spaces between the columns and the result occurred in KNIME output but not in text file.
KNIME Output:

Text File Output:

while extracting we used CSV Writer node with space as column delimiter with 2 spaces.

could you please help me in resolving this issue.

Subramanyam Kinthada.

Hi @Subramanyam , well I went with what you originally wrote and showed in your very first post

and all I needed to know after that was how the input data of what you showed was.

Based on what you are explaining now, it’s a totally different approach that’s needed. It’s not the same requirements! It’s a complete redo in the end. Why do most people do that? :unamused: :pensive: :sob:

I always say this: “Help us help you. The more details/info you provide, the more precise the solution will be”. It serves no purpose rushing and leaving key information out. If anything, it’s a liability to do so.

You are lucky that this is an interesting challenge enough for me to not walk away from it.

This is how I would do it:

After concatenating everything, this is how it looks like in Knime before being written to a file:

And that’s how the file looks like:

Here’s the new workflow: reduce spaces between two columns.knwf (23.8 KB)

@mlauber71 : No need to use a loop to generate the spaces. You can use padding (padLeft() or padRight()) to generate the spaces :wink:
This is what I used: join($Row0$, padLeft("", $spaces$, " "))


Hi @bruno29a ,

Thanks a lot for providing the solution. I have achieved the perfect result.

Subramanyam Kinthada

1 Like

No problem @Subramanyam , happy to help

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.