This should be straight-forward, but I cannot figure it out. If I want to replace an A or B with a C using sed the code could potentially be:
$ echo AAXXAAYYBB | sed 's/[AB]/C/g'
CCXXCCYYCC
This results in all A's and B's converted to C's.
What I'd like to do is replace "A" with either one of two (or potentially more) variables:
Input:
AAXXAAYYBB
Code:
sed 's/A/[BC]/g'
Output (where the substitution of B or C is random):
BCXXCBYYBB
But this code will only change A's to...
$ echo AAXXAAYYBB | sed 's/A/[BC]/g'
[BC][BC]XX[BC][BC]YYBB
I'm trying to avoid PERL here if possible. Does anyone have an idea how to fix this?
s
command insed
is text, not an expression. – Kusalananda Jun 20 '19 at 21:41B
andC
, you can use justs/A/C/g
; you're just randomly choosingC
every time. Seriously, if you want to simulate some mutation or such, you should try a bit harder to define your problem and requirements. – Jun 21 '19 at 09:54