Convert few columns to rows

Hi!
Does anybody help me in converting following data:

INPUT looks like this:

20. 100.        
30  200.
40. 400.
50. 100.        
60.  200.
70. 400.
80. 200.
150. 210.
30. 100.

OUTPUT should look like this:

20. 100.     30  200.   40. 400.    50. 100.        
60.  200.     70. 400.   80. 200.   150. 210.
30. 100.

Thanks a lot for your help!

Assuming your input is same as you have provided..

xargs -n 8 < file
1 Like

Simplest what one can do is..

 
printf "%s %s %s %s %s %s %s %s\n" $(cat filename)
1 Like

It works but I would like to have %8.2f for each value. Thanks!

---------- Post updated at 06:17 AM ---------- Previous update was at 05:12 AM ----------

Wonderful its very simple, In case if I have only 2 values left in the last row it is simply writing zeros in other 6 places. If I use a conditional statement qual to NF it will work.

Try this..
I know this is not the best way. you have to handle some spacing...:slight_smile:

xargs -n 8 < file | awk '{if(! max){max=NF}{for(i=1;i<=max;i++){if($i == ""){ $i=0}}}}1' 

first of all Thanks! unfortunately, I still have zeros at the end.

---------- Post updated at 08:19 AM ---------- Previous update was at 07:08 AM ----------

Here is the working script

awk 'BEGIN {
i = 1}
{
printf "%8.2e %8.2e ", $1,$2
i = i+1
if (i == 5)
{
i=1; printf "\n" 
}
}
END {
}' file