Let's consider this test file with arrays with 3 rows each:
$ cat File 1 2 3 4 5 6 a b c d e f A B C D E F
Now, let's concatenate the arrays:
$ awk -v nr=3 '{a[NR]=$0} END{for (i=1;i<=nr;i++) {for (j=i;j<=NR;j+=nr) printf "%s ",a[j]; print""}}' File 1 2 a b A B 3 4 c d C D 5 6 e f E F
In your data file, there are 128 rows per array. In that case, run:
awk -v nr=128 '{a[NR]=$0} END{for (i=1;i<=nr;i++) {for (j=i;j<=NR;j+=nr) printf "%s ",a[j]; print""}}' File
How it works
-v nr=128
This sets the variable nr
to the number of rows per array.
a[NR]=$0
NR
is the line number. We save each row (line) in the array a
.
END{for (i=1;i<=nr;i++) {for (j=i;j<=NR;j+=nr) printf "%s ",a[j]; print""}}
After we have read in all the rows, this writes them out again in the form that you want.
To do this, we loop over the variable i
starting with i=1
and finishing with i=nr
. For each i
, we print the new row i
. For each i
value, we loop over j
where j
is the number of row of the old file that belongs on row i
of the new file`.
Variation
Although it makes it more difficult for a beginner to read, a ternary statement can be used to give a slight improvement in the formatting:
$ awk -v nr=3 '{a[NR]=$0} END{for (i=1;i<=nr;i++) for (j=i;j<=NR;j+=nr) printf "%s%s",a[j],(j+nr<=NR?" ":"\n")}' File 1 2 a b A B 11 22 3 4 c d C D 33 44 5 6 e f E F 55 66
j+nr<=NR?" ":"\n"
is a ternary statement. It returns a space if j+nr<=NR
. Otherwise, it returns a newline.
tr '\n' ' ' <file1 >file2
but I don't think that's what you want. (Or is it?)split -l128 file1
and then re-assemble them usingpaste
e.g (assuming the default split prefix, and brace expansion)paste xa{a..y} > file2