If you want all combinations, why isn't GBCAGCD included in the desired output?
You haven't said what operating system you're using, and some of the suggestions you have received so far will do what was requested on Linux systems, but not on most BSD and UNIX systems.
If you do want all combinations, you might try something more like:
printf '%s\n' ABCAACD A AA AAAA | awk -FA '
{ printf("Input:\t%s\n", $0)
for(i = 1; i < 2 ^ (NF - 1); i++) {
x = i
for(j = 1; j < NF; j++) {
printf("%s%s", $j, (x % 2) ? "G" : "A")
x = int(x / 2)
}
printf("%s%s", $NF, ORS)
}
}'
which produces the output:
Input: ABCAACD
GBCAACD
ABCGACD
GBCGACD
ABCAGCD
GBCAGCD
ABCGGCD
GBCGGCD
Input: A
G
Input: AA
GA
AG
GG
Input: AAAA
GAAA
AGAA
GGAA
AAGA
GAGA
AGGA
GGGA
AAAG
GAAG
AGAG
GGAG
AAGG
GAGG
AGGG
GGGG
If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .