I have 2 files like below:
file1:
a1,b1,c1,d1,e1,f1,g1,h1
a2,b2,c2,d2,e2,f2,g2,h2
a3,b3,c3,d3,e3,f3,g3,h3
a4,b4,c4,d4,e4,f4,g4,h4
file2:
x1,y1,z1
x2,y2,z2
x3,y3,z3
x4,y4,z4
I want to read simultaneously from both and output the variables in a pattern like below:
a1,b1,c1,d1,x1,e1,f1,y1,g1,z1,h1
a2,b2,c2,d2,x2,e2,f2,y2,g2,z2,h2
a3,b3,c3,d3,x3,e3,f3,y3,g3,z3,h3
a4,b4,c4,d4,x4,e4,f4,y4,g4,z4,h4
Good news - I've managed to achieve it !!
Bad news - Too many arrays and while loops (too much computation!). I am looking for something simpler as the script will have to read through much data (4k lines and 1M words).
Limitation - BASH shell (probably not a limitation!)
This is what I've done
exec 5<file1 # Open file into FD 5
exec 6<file2 # Open file into FD 6
while IFS=$"," read -r line1 <&5
IFS=$"," read -r line2 <&6
do
array1=( `echo $line1` )
array2=( `echo $line2` )
array3=("${array1[@]}","${array2[@]}")
echo ${array3[@]} >> tmpline
done
while IFS="," read var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11
do
echo -e "$var1,$var2,$var3,$var4,$var9,$var5,$var6,$var10,$var8,$var11,$var9" >> tcomb
done < tmpline
exec 5<&- # Close FD 5
exec 6<&- # Close FD 6
Thanks in advance -- I'm waiting patiently :) !!