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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Something like this? Worked with your sample data:
paste file{1,2} | awk '{for (i=1;i<=NF/2; i++){printf "%s:%st",$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
Method 2
awk '{
getline f2 < "file2"
split(f2, a)
for (i=1; i<=NF; i++)
printf "%s:%st", $i, a[i]
print ""
}' file1
Method 3
A slightly different approach:
paste -d: <(xargs -n1 <file1) <(xargs -n1 <file2) | xargs -n 3
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0