Convert a text file into columns
awk, linux, unix
Solution
If you are not limited to `awk` but have GNU core-utils (cygwin, native, ..) then the simplest solution is to use `pr`:
pr -ts" " --columns 3 file
Problem
Let's assume I have scientific data, all numbers arranged in a single column but representing an intensities matrix of n (width) by m (height). The column of the input file has in total n * m rows. An input example may look like that: ``` 1 2 3 ...... 30 ``` The new output should be such that I have n new columns with m rows. Sticking to my example with 30 fields input and n = 3, m = 10, I would need an output file like this (separator does not matter much, could be a blank, a tab etc.): ``` 1 11 21 2 12 22 ... ... ... 10 20 30 ``` I use gawk under Windows. Please note that there are no special `FS`, more real-world examples are like 60 * 60 or bigger.