The way awk works is that by default it steps through each line of text and splits every space-separated item into fields, in this case we have fields $2, $3,and $4 of interest. Now what if we could store each $2 field of each line into a list and then print it ? That's where arrays can help.
Treating the body of an awk code as one big while loop, we can separate fields 2,3,and 4 into appropriate arrays. With each line, arrays will get filled. So we basically sort everything into columns(arrays) as we go though lines. Once done, we can go through a loop printing each colum(array) separately, while just adding text "Column#".
$ awk '{ array1[NR]=$2;array2[NR]=$3;array3[NR]=$4} END{for(i=1;i<=NR;i++){print "Column"i" "array1[i]};printf "\n";for(i=1;i<=NR;i++){print "Column"i" "array2[i]}; printf"\n"; for(i=1;i<=NR;i++){print "Column"i" "array3[i] };printf "\n" }' columns.txt
Column1 a
Column2 1
Column3 x
Column1 b
Column2 2
Column3 y
Column1 c
Column2 3
Column3 z
Of course that one long line is a bit awkward to use (no awk puns intended). We can put everything into a script:
#!/usr/bin/awk -f
{ array1[NR]=$2;array2[NR]=$3;array3[NR]=$4 }
END{
for(i=1;i<=NR;i++){
print "Column"i" "array1[i]};printf "\n";
for(i=1;i<=NR;i++){
print "Column"i" "array2[i]}; printf"\n";
for(i=1;i<=NR;i++){
print "Column"i" "array3[i] };printf "\n"
}
Call that script columnate.awk, change permissions to executable with chmod +x columnate.awk and run it with any text file as a parameter:
$ ./columnate.awk columns.txt
Column1 a
Column2 1
Column3 x
Column1 b
Column2 2
Column3 y
Column1 c
Column2 3
Column3 z
Col1 aCol2 1Col3 x.head Src.txt