I am trying to write different arrays into a csv file ($file) columns.
Each array has the same number of values.
For example, arr1 and arr2 have 3 values each
arr1=( 23 45 34 )
arr2=( "abc,d" ef g )
I tried the following code but I'm getting the wrong results
for i in "${!arr1[@]}"; do
echo "${arr1[i]}, ${arr2[i]}" >> $file
done
I'm getting the following where col1, col2 and col3 are 3 columns.
col1 col2 col3
23 "abc d"
45 ef
34 g
but the desired result is
col1 col2
23 "abc,d"
45 ef
34 g
It seems like the embedded coma in "abc,d" creates a problem. Anyone knows a way around this or any better way to do this?
Thank you in advance!