I added 004 D to file2 so we'd have a non-obvious case to test with. Given that, either this:
$ sort -k1,1 -s file1 file2 |
awk '
$1 != prev { if (NR>1) print ""; printf "%s", $1; prev=$1 }
{ printf " %s", $2 }
END { print "" }
'
001 A
002 B D
003 C D
004 D D
005 E
006 F
or this:
$ sort -k1,1 -s file1 file2 |
awk '
$1 != prev{if (NR>1) print ""; printf "%s", $1; prev=$1; delete seen }
!seen[$2]++ { printf " %s", $2 }
END { print "" }
'
001 A
002 B D
003 C D
004 D
005 E
006 F
depending on how you want duplicate values for the same key handled. Just list as many files as you like on the sort line. The above assumes GNU sort for -s to retain input order for the same keys, if you don't have that and actually need it there are simple alternatives. You can also trivially tweak that to always get the A B C, etc. to be in alphabetic order on each output line rather than the order they occur in each input file if you like, e.g.:
$ head file*
==> file1 <==
001 A
002 E
003 F
004 D
==> file2 <==
002 D
003 D
004 D
005 E
006 F
==> file3 <==
001 A
002 E
003 C
004 D
$ sort -s file* | awk '$1 != prev{if (NR>1) print ""; prev=$1; delete seen; printf "%s", $1} !seen[$2]++{printf " %s", $2} END{print ""}'
001 A
002 D E
003 C D F
004 D
005 E
006 F
{print $1, a[$1]$2}to{print $1, a[$1] OFS $2}or indeed{print $1, a[$1] "any string here" $2}004 Dalso existed in file2 -004 Dor004 D D? Does the order of output lines matter and, if so, what should it be based on?@EdMortonin the comment then I don't get notified that you've posted anything for me to read.