Text Processing – How to Merge Two Files One Column at a Time

awkdatamergesedtext processing

I have 2 large files (3000 columns, 15000 rows) of the following format

file1 (tab-separated):

1/0 0/0 0/0
0/0 1/1 0/0
1/1 0/1 0/0

file2 (tab-separated):

3 5 2
1 7 10
3 4 3

I'd like to combine the values from the first column of each file with a ":" separator, then move on to the second, third, etc. columns.
Desired output (tab-separated):

1/0:3 0/0:5 0/0:2
0/0:1 1/1:7 0/0:10
1/1:3 0/1:4 0/0:3

Efficiency isn't critical, so any language is fine. I apologize if this has been asked before.

Best Answer

Something like this? Worked with your sample data:

paste  file{1,2} | awk '{for (i=1;i<=NF/2; i++){printf "%s:%s\t",$i,$(NF/2+i)};printf "\n"}'
1/0:3   0/0:5   0/0:2
0/0:1   1/1:7   0/0:10
1/1:3   0/1:4   0/0:3
Related Question