0

I have an input in form A[BCDE]GT. I would like my output to be:

ABGT
ACGT
ADGT
AEGT

I have tried to use echo, printf, trying to find something that might work. Does anyone know some command that will help to execute this?

2
  • 2
    try: echo A{B..E}GT – Isaac Apr 29 at 2:02
  • In the general case, it's not possible to generate all possible strings that matches a regular expression. How locked into the particular format are you? Could you possible go along with a modified format, such as the one Isaac suggests, or A{B,C,D,E}FG? Regular expressions are for matching against texts, whereas brace expansions (the example in these comments) are for generating strings. – Kusalananda Apr 29 at 8:50
1

With zsh instead of bash, you can do something approaching by replacing [BCDE] with {BCDE}:

$ set -o braceccl
$ print -l A{BCDE}GT
ABGT
ACGT
ADGT
AEGT

If your input is guaranteed to contain only word characters and [, ] characters:

set -o braceccl
input='A[BCDE]GT'
eval "output=( ${${${input//[^][[:IDENT:]]}//\[/{}//\]/\}} )"
print -l $output
0
-1

You can use this, in shell with a script.

X[0]="b"
X[1]="c"
X[2]="d"
X[3]="e"
for i in {0..3}
do
echo A${X[$i]}\GT
done
1
  • 1
    Note that they have the input in the form A[BCDE]GT. How do you suggest applying your code given that string? – Kusalananda Apr 29 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.