a.txt
aaa bbb ccc fddf
ddd eee fff
b.txt
111 222 333
444 555 666
Mix their output like this:
aaa 111 bbb 222 ccc 333
ddd 444 eee 555 fff 666
aaa 111 bbb 222 ccc 333
ddd 444 eee 555 fff 666
My ruby solution:
atext=File.readlines('a.txt').map {|line| line.split}
btext=File.readlines('b.txt').map {|line| line.split}
out=[]
(btext.size > atext.size ? btext.size : atext.size).times do |i|
if btext[i].nil?
out<<atext[i]
elsif atext[i].nil?
out<<btext[i]
else
out<<atext[i].zip(btext[i]).flatten.compact
end
end
File.open("out.txt", "w+") do |f|
out.each { |element| f.puts(element.join(' '))}
end