From column to table

Hi,
I have an ascii file containing information. This file is n x m lines.

Is there a way to generate an ascii file where the information is stored as n x m table instead? The m columns should be tab separated.
Thanks a lot,
Sarah

Please give an example of desired input and output

It's quite a long file (above 100000) but it is something like this:
Input:

Output:

Thank you

First of all make one directory and copy input file in it. Then go to that directory and perform following steps.

1.> Split the input file using split command in number of rows that you want.

split -l 50 inputFile        # for 50 rows

2.> remove input file from current directory.

3.> then use paste command to merge them.

paste `ls` > outputFile
1 Like

Have a look at this thread:

Maybe danmero's code will feet your needs?

$ awk '{_=NR%10}_{a[_]=((a[_])?a[_]FS:x)$1;l=(_>l)?_:l}END{for(i=0;++i<=l;)print a}' file
1.08E-04 1.45E-06 0.00E+00 3.45E-06 9.99E-06
2.47E-06 3.91E-06 1.81E-06 1.52E-06 5.69E-06
1.55E-06 2.13E-06 3.63E-06 2.71E-06 4.29E-06
1.38E-06 6.60E-06 1.39E-06 2.92E-06 1.59E-06
1.50E-06 3.37E-06 5.74E-06 1.12E-06 0.00E+00
1.22E-06 5.96E-06 2.16E-06 4.55E-06 0.00E+00
3.54E-06 5.46E-06 4.08E-06 2.95E-06 0.00E+00
1.87E-06 1.54E-06 0.00E+00 2.34E-06 0.00E+00
1.49E-06 4.74E-06 9.31E-07 2.31E-06 3.17E-06

with paste command but not that versatile..

cat inputfile | paste - - - - > outfile

In the example there is a column of number but it can be also text. The solution of R0H0N works even if it is a bit "clumsy".
Thank you,

awk '{r=(NR-1)%n;A[r]=A[r](A[r]?FS:x)$1}END{for(i=0;i<=n-1;i++)print A}' n=10 infile
2 Likes

Thanks Scrutinizer, how do I get tab spaces columns instead of space spaced columns?

paste -d"^I" `ls`

this will paste using tab delimiter.

Hi, try:

awk '{r=(NR-1)%n;A[r]=A[r](A[r]?"\t":x)$1}END{for(i=0;i<=n-1;i++)print A}' n=10 infile

Thank you all