For you it needs to conditional logic inside For-each with variables storing the data as you go through the iteration.
For example, Let’s say you are iterating through rows and you found a non-empty column you just add it to your new output data row and keep on doing the same. At the end of iteration you check if your output data row is all filled and if yes move to next row and continue iteration else simply continue iteration.
Wow this is what I want ! I have tried my solution, but using a lot of if statement here. However, the output is closed but not exactly what I want. But your solution is exactly like what I want !