[Solved] bash, merge two comma separated variables values to single variable


This is a simple extension of Iterate over two arrays simultaneously in bash, combined with How to split a string into an array in bash.

IFS=, read -ra sbi_arr <<<"$SBI" # convert SBI string to an array
IFS=, read -ra mem_arr <<<"$MEM" # convert MEM string to an array

out=                             # initialize output variable
for idx in "${!sbi_arr[@]}"; do  # iterate by indices
  out+="${sbi_arr[$idx]}_${mem_arr[$idx]}," # append to output
done
out=${out%,}                     # strip trailing comma from output

echo "Output is: $out"

0

solved bash, merge two comma separated variables values to single variable