Changing the format of two columns using AWK

$ awk -F '[ ,]' '{ for (i = 2; i <= NF; ++i) print $1, $i }' file
A 1
A 2
B 3
B 2
B 5
C 6
C 7
D 1
D 3
D 5
D 8

This treats the lines as consisting of fields delimited by either spaces or commas. For each line, the awk program iterates over the second field onwards to the end of the line. For each field, it outputs the first field on the line together with the current field.


awk '{gsub(/,/,  "\n" $1 " "); print}' file

In this solution we are just replacing every "," by "\n$1 "