Using sed to replace “A” with a “B” or “C”How to generate a random string?Replace matches with multiline string using sedReorder Multiple Line Blocks with Sedreplace $ with £ using sed commandHow to replace symbol || with |“”| using sedReplace some text with sedReplace a range of text with special characters using sedReplace special characters with sedSearch and replace sentence with spaces using sed commandFind and replace using regex with sedUsing sed to replace numbers with @ inserts @ between every character
Can ADFS connect to other SSO services?
Sci fi short story, robot city that nags people about health
Require advice on power conservation for backpacking trip
Does squid ink pasta bleed?
Interaction between Leyline of Anticipation and Teferi, Time Raveler
Why doesn't a marching band have strings?
Should I prioritize my 401(k) over my student loans?
Cascading Repair Costs following Blown Head Gasket on a 2004 Subaru Outback
If the world have massive single giant world tree can it stop earthquake?
How do I set an alias to a terminal line?
“D’entre eux” to mean “of them”
Iterate MapThread with matrices
Iterate over colors on next pie chart with pgf-pie
Computing a trigonometric integral
Why cruise at 7000' in an A319?
In the Marvel universe, can a human have a baby with any non-human?
How does a blind passenger not die, if driver becomes unconscious
Why do all the teams that I have worked with always finish a sprint without completion of all the stories?
Where can I find a database of galactic spectra?
Can humans ever directly see a few photons at a time? Can a human see a single photon?
What is the origin of Scooby-Doo's name?
STM Microcontroller burns every time
What's currently blocking the construction of the wall between Mexico and the US?
Find the probability that the 8th woman to appear is in 17th position.
Using sed to replace “A” with a “B” or “C”
How to generate a random string?Replace matches with multiline string using sedReorder Multiple Line Blocks with Sedreplace $ with £ using sed commandHow to replace symbol || with |“”| using sedReplace some text with sedReplace a range of text with special characters using sedReplace special characters with sedSearch and replace sentence with spaces using sed commandFind and replace using regex with sedUsing sed to replace numbers with @ inserts @ between every character
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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?
sed random
New contributor
add a comment |
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?
sed random
New contributor
The replacement text in thes
command insed
is text, not an expression.
– Kusalananda♦
8 hours ago
2
It would be fairly easy to make the replacements alternate between B and C (using conditional branching)
– steeldriver
7 hours ago
Hello. Thank you for reviewing my question. I am going to try to see if I can make this work without using perl based on your suggestions. I am trying write a .sh that I hope anyone would be able to modify. If I have to add perl, it might be a little complicated for potential users.
– Anthony D
5 hours ago
add a comment |
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?
sed random
New contributor
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?
sed random
sed random
New contributor
New contributor
edited 7 hours ago
Tomasz
10.8k7 gold badges35 silver badges73 bronze badges
10.8k7 gold badges35 silver badges73 bronze badges
New contributor
asked 8 hours ago
Anthony DAnthony D
111 bronze badge
111 bronze badge
New contributor
New contributor
The replacement text in thes
command insed
is text, not an expression.
– Kusalananda♦
8 hours ago
2
It would be fairly easy to make the replacements alternate between B and C (using conditional branching)
– steeldriver
7 hours ago
Hello. Thank you for reviewing my question. I am going to try to see if I can make this work without using perl based on your suggestions. I am trying write a .sh that I hope anyone would be able to modify. If I have to add perl, it might be a little complicated for potential users.
– Anthony D
5 hours ago
add a comment |
The replacement text in thes
command insed
is text, not an expression.
– Kusalananda♦
8 hours ago
2
It would be fairly easy to make the replacements alternate between B and C (using conditional branching)
– steeldriver
7 hours ago
Hello. Thank you for reviewing my question. I am going to try to see if I can make this work without using perl based on your suggestions. I am trying write a .sh that I hope anyone would be able to modify. If I have to add perl, it might be a little complicated for potential users.
– Anthony D
5 hours ago
The replacement text in the
s
command in sed
is text, not an expression.– Kusalananda♦
8 hours ago
The replacement text in the
s
command in sed
is text, not an expression.– Kusalananda♦
8 hours ago
2
2
It would be fairly easy to make the replacements alternate between B and C (using conditional branching)
– steeldriver
7 hours ago
It would be fairly easy to make the replacements alternate between B and C (using conditional branching)
– steeldriver
7 hours ago
Hello. Thank you for reviewing my question. I am going to try to see if I can make this work without using perl based on your suggestions. I am trying write a .sh that I hope anyone would be able to modify. If I have to add perl, it might be a little complicated for potential users.
– Anthony D
5 hours ago
Hello. Thank you for reviewing my question. I am going to try to see if I can make this work without using perl based on your suggestions. I am trying write a .sh that I hope anyone would be able to modify. If I have to add perl, it might be a little complicated for potential users.
– Anthony D
5 hours ago
add a comment |
4 Answers
4
active
oldest
votes
Plenty of ways to skin this particular cat once we resort to scripting, but here is something I threw together - It may not be pretty, (and relies on a bash shell!) but it might help you out:
#!/bin/bash
TEXT="AAXXAAYYBB"
echo "Start: $TEXT"
# So long as there are un-converted 'A' in the input string...
while [[ "$TEXT" =~ A ]]
do
# .. convert one 'A' to a random choice of either 'B' or 'C'
TEXT=$(echo $TEXT | sed -e "s/A/$(((RANDOM%2>0))&&echo B || echo C)/")
# lets show how we are progressing...
echo "Progress: $TEXT"
done
# No more 'A' in the input string, we are done:
echo "End: $TEXT"
Example output:
First run:
Start: AAXXAAYYBB
Progress: BAXXAAYYBB
Progress: BBXXAAYYBB
Progress: BBXXBAYYBB
Progress: BBXXBCYYBB
End: BBXXBCYYBB
Second run:
Start: AAXXAAYYBB
Progress: CAXXAAYYBB
Progress: CBXXAAYYBB
Progress: CBXXCAYYBB
Progress: CBXXCBYYBB
End: CBXXCBYYBB
New contributor
Nice idea (+1)! You should quote your variables though (echo "$TEXT"
) to preserve whitespace. Also, even better isprintf
to deal with escape characters. Even better is a herestring (<<< "$TEXT"
) to not open a new process.
– Sparhawk
6 hours ago
add a comment |
It is possible to replace the first match of an string with:
$str/A/...
And, it is possible to generate a random (not a cryptographic secure number) value with:
r=(B C)
$r[RANDOM%2]
Each time the variable r
is expanded.
So:
#!/bin/bash
str=AAXXAAYYBB
r=(B C)
while [[ $str =~ A ]]; do
str=$str/A/"$r[RANDOM%2]"
done
echo "str=$str"
Will generate a random result each time it is called.
add a comment |
It is much more "straightforward" to replace A or B with C than to replace A with B or C, as the or in the former case has nothing to do with randomness, while in the latter it's based on it. So while the former could be broken down into two simple steps:
- replace A with C
- replace B with C
In the latter case there's the whole lot of deciding which one should be the replacement in every particular case, B or C? What's the basis? How random should the randomness be?
sed
doesn't offer any random operations as far as I know. (While Perl should be a good tool.)
See related:
How to generate a random string?
And other random tagged questions
add a comment |
Not Sed, but avoids Perl:
$ echo AAXXAAYYBB | gawk '
BEGINsrand()
n = patsplit($0,a,/A/,s);
for(i=1;i<=n;i++) printf("%s%s", rand() < 0.5 ? "B" : "C", s[i]);
print ""
'
CBXXCCYYBB
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Anthony D is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f526129%2fusing-sed-to-replace-a-with-a-b-or-c%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Plenty of ways to skin this particular cat once we resort to scripting, but here is something I threw together - It may not be pretty, (and relies on a bash shell!) but it might help you out:
#!/bin/bash
TEXT="AAXXAAYYBB"
echo "Start: $TEXT"
# So long as there are un-converted 'A' in the input string...
while [[ "$TEXT" =~ A ]]
do
# .. convert one 'A' to a random choice of either 'B' or 'C'
TEXT=$(echo $TEXT | sed -e "s/A/$(((RANDOM%2>0))&&echo B || echo C)/")
# lets show how we are progressing...
echo "Progress: $TEXT"
done
# No more 'A' in the input string, we are done:
echo "End: $TEXT"
Example output:
First run:
Start: AAXXAAYYBB
Progress: BAXXAAYYBB
Progress: BBXXAAYYBB
Progress: BBXXBAYYBB
Progress: BBXXBCYYBB
End: BBXXBCYYBB
Second run:
Start: AAXXAAYYBB
Progress: CAXXAAYYBB
Progress: CBXXAAYYBB
Progress: CBXXCAYYBB
Progress: CBXXCBYYBB
End: CBXXCBYYBB
New contributor
Nice idea (+1)! You should quote your variables though (echo "$TEXT"
) to preserve whitespace. Also, even better isprintf
to deal with escape characters. Even better is a herestring (<<< "$TEXT"
) to not open a new process.
– Sparhawk
6 hours ago
add a comment |
Plenty of ways to skin this particular cat once we resort to scripting, but here is something I threw together - It may not be pretty, (and relies on a bash shell!) but it might help you out:
#!/bin/bash
TEXT="AAXXAAYYBB"
echo "Start: $TEXT"
# So long as there are un-converted 'A' in the input string...
while [[ "$TEXT" =~ A ]]
do
# .. convert one 'A' to a random choice of either 'B' or 'C'
TEXT=$(echo $TEXT | sed -e "s/A/$(((RANDOM%2>0))&&echo B || echo C)/")
# lets show how we are progressing...
echo "Progress: $TEXT"
done
# No more 'A' in the input string, we are done:
echo "End: $TEXT"
Example output:
First run:
Start: AAXXAAYYBB
Progress: BAXXAAYYBB
Progress: BBXXAAYYBB
Progress: BBXXBAYYBB
Progress: BBXXBCYYBB
End: BBXXBCYYBB
Second run:
Start: AAXXAAYYBB
Progress: CAXXAAYYBB
Progress: CBXXAAYYBB
Progress: CBXXCAYYBB
Progress: CBXXCBYYBB
End: CBXXCBYYBB
New contributor
Nice idea (+1)! You should quote your variables though (echo "$TEXT"
) to preserve whitespace. Also, even better isprintf
to deal with escape characters. Even better is a herestring (<<< "$TEXT"
) to not open a new process.
– Sparhawk
6 hours ago
add a comment |
Plenty of ways to skin this particular cat once we resort to scripting, but here is something I threw together - It may not be pretty, (and relies on a bash shell!) but it might help you out:
#!/bin/bash
TEXT="AAXXAAYYBB"
echo "Start: $TEXT"
# So long as there are un-converted 'A' in the input string...
while [[ "$TEXT" =~ A ]]
do
# .. convert one 'A' to a random choice of either 'B' or 'C'
TEXT=$(echo $TEXT | sed -e "s/A/$(((RANDOM%2>0))&&echo B || echo C)/")
# lets show how we are progressing...
echo "Progress: $TEXT"
done
# No more 'A' in the input string, we are done:
echo "End: $TEXT"
Example output:
First run:
Start: AAXXAAYYBB
Progress: BAXXAAYYBB
Progress: BBXXAAYYBB
Progress: BBXXBAYYBB
Progress: BBXXBCYYBB
End: BBXXBCYYBB
Second run:
Start: AAXXAAYYBB
Progress: CAXXAAYYBB
Progress: CBXXAAYYBB
Progress: CBXXCAYYBB
Progress: CBXXCBYYBB
End: CBXXCBYYBB
New contributor
Plenty of ways to skin this particular cat once we resort to scripting, but here is something I threw together - It may not be pretty, (and relies on a bash shell!) but it might help you out:
#!/bin/bash
TEXT="AAXXAAYYBB"
echo "Start: $TEXT"
# So long as there are un-converted 'A' in the input string...
while [[ "$TEXT" =~ A ]]
do
# .. convert one 'A' to a random choice of either 'B' or 'C'
TEXT=$(echo $TEXT | sed -e "s/A/$(((RANDOM%2>0))&&echo B || echo C)/")
# lets show how we are progressing...
echo "Progress: $TEXT"
done
# No more 'A' in the input string, we are done:
echo "End: $TEXT"
Example output:
First run:
Start: AAXXAAYYBB
Progress: BAXXAAYYBB
Progress: BBXXAAYYBB
Progress: BBXXBAYYBB
Progress: BBXXBCYYBB
End: BBXXBCYYBB
Second run:
Start: AAXXAAYYBB
Progress: CAXXAAYYBB
Progress: CBXXAAYYBB
Progress: CBXXCAYYBB
Progress: CBXXCBYYBB
End: CBXXCBYYBB
New contributor
New contributor
answered 7 hours ago
bunnymjhbunnymjh
211 bronze badge
211 bronze badge
New contributor
New contributor
Nice idea (+1)! You should quote your variables though (echo "$TEXT"
) to preserve whitespace. Also, even better isprintf
to deal with escape characters. Even better is a herestring (<<< "$TEXT"
) to not open a new process.
– Sparhawk
6 hours ago
add a comment |
Nice idea (+1)! You should quote your variables though (echo "$TEXT"
) to preserve whitespace. Also, even better isprintf
to deal with escape characters. Even better is a herestring (<<< "$TEXT"
) to not open a new process.
– Sparhawk
6 hours ago
Nice idea (+1)! You should quote your variables though (
echo "$TEXT"
) to preserve whitespace. Also, even better is printf
to deal with escape characters. Even better is a herestring (<<< "$TEXT"
) to not open a new process.– Sparhawk
6 hours ago
Nice idea (+1)! You should quote your variables though (
echo "$TEXT"
) to preserve whitespace. Also, even better is printf
to deal with escape characters. Even better is a herestring (<<< "$TEXT"
) to not open a new process.– Sparhawk
6 hours ago
add a comment |
It is possible to replace the first match of an string with:
$str/A/...
And, it is possible to generate a random (not a cryptographic secure number) value with:
r=(B C)
$r[RANDOM%2]
Each time the variable r
is expanded.
So:
#!/bin/bash
str=AAXXAAYYBB
r=(B C)
while [[ $str =~ A ]]; do
str=$str/A/"$r[RANDOM%2]"
done
echo "str=$str"
Will generate a random result each time it is called.
add a comment |
It is possible to replace the first match of an string with:
$str/A/...
And, it is possible to generate a random (not a cryptographic secure number) value with:
r=(B C)
$r[RANDOM%2]
Each time the variable r
is expanded.
So:
#!/bin/bash
str=AAXXAAYYBB
r=(B C)
while [[ $str =~ A ]]; do
str=$str/A/"$r[RANDOM%2]"
done
echo "str=$str"
Will generate a random result each time it is called.
add a comment |
It is possible to replace the first match of an string with:
$str/A/...
And, it is possible to generate a random (not a cryptographic secure number) value with:
r=(B C)
$r[RANDOM%2]
Each time the variable r
is expanded.
So:
#!/bin/bash
str=AAXXAAYYBB
r=(B C)
while [[ $str =~ A ]]; do
str=$str/A/"$r[RANDOM%2]"
done
echo "str=$str"
Will generate a random result each time it is called.
It is possible to replace the first match of an string with:
$str/A/...
And, it is possible to generate a random (not a cryptographic secure number) value with:
r=(B C)
$r[RANDOM%2]
Each time the variable r
is expanded.
So:
#!/bin/bash
str=AAXXAAYYBB
r=(B C)
while [[ $str =~ A ]]; do
str=$str/A/"$r[RANDOM%2]"
done
echo "str=$str"
Will generate a random result each time it is called.
answered 6 hours ago
IsaacIsaac
13.4k1 gold badge21 silver badges59 bronze badges
13.4k1 gold badge21 silver badges59 bronze badges
add a comment |
add a comment |
It is much more "straightforward" to replace A or B with C than to replace A with B or C, as the or in the former case has nothing to do with randomness, while in the latter it's based on it. So while the former could be broken down into two simple steps:
- replace A with C
- replace B with C
In the latter case there's the whole lot of deciding which one should be the replacement in every particular case, B or C? What's the basis? How random should the randomness be?
sed
doesn't offer any random operations as far as I know. (While Perl should be a good tool.)
See related:
How to generate a random string?
And other random tagged questions
add a comment |
It is much more "straightforward" to replace A or B with C than to replace A with B or C, as the or in the former case has nothing to do with randomness, while in the latter it's based on it. So while the former could be broken down into two simple steps:
- replace A with C
- replace B with C
In the latter case there's the whole lot of deciding which one should be the replacement in every particular case, B or C? What's the basis? How random should the randomness be?
sed
doesn't offer any random operations as far as I know. (While Perl should be a good tool.)
See related:
How to generate a random string?
And other random tagged questions
add a comment |
It is much more "straightforward" to replace A or B with C than to replace A with B or C, as the or in the former case has nothing to do with randomness, while in the latter it's based on it. So while the former could be broken down into two simple steps:
- replace A with C
- replace B with C
In the latter case there's the whole lot of deciding which one should be the replacement in every particular case, B or C? What's the basis? How random should the randomness be?
sed
doesn't offer any random operations as far as I know. (While Perl should be a good tool.)
See related:
How to generate a random string?
And other random tagged questions
It is much more "straightforward" to replace A or B with C than to replace A with B or C, as the or in the former case has nothing to do with randomness, while in the latter it's based on it. So while the former could be broken down into two simple steps:
- replace A with C
- replace B with C
In the latter case there's the whole lot of deciding which one should be the replacement in every particular case, B or C? What's the basis? How random should the randomness be?
sed
doesn't offer any random operations as far as I know. (While Perl should be a good tool.)
See related:
How to generate a random string?
And other random tagged questions
answered 7 hours ago
TomaszTomasz
10.8k7 gold badges35 silver badges73 bronze badges
10.8k7 gold badges35 silver badges73 bronze badges
add a comment |
add a comment |
Not Sed, but avoids Perl:
$ echo AAXXAAYYBB | gawk '
BEGINsrand()
n = patsplit($0,a,/A/,s);
for(i=1;i<=n;i++) printf("%s%s", rand() < 0.5 ? "B" : "C", s[i]);
print ""
'
CBXXCCYYBB
add a comment |
Not Sed, but avoids Perl:
$ echo AAXXAAYYBB | gawk '
BEGINsrand()
n = patsplit($0,a,/A/,s);
for(i=1;i<=n;i++) printf("%s%s", rand() < 0.5 ? "B" : "C", s[i]);
print ""
'
CBXXCCYYBB
add a comment |
Not Sed, but avoids Perl:
$ echo AAXXAAYYBB | gawk '
BEGINsrand()
n = patsplit($0,a,/A/,s);
for(i=1;i<=n;i++) printf("%s%s", rand() < 0.5 ? "B" : "C", s[i]);
print ""
'
CBXXCCYYBB
Not Sed, but avoids Perl:
$ echo AAXXAAYYBB | gawk '
BEGINsrand()
n = patsplit($0,a,/A/,s);
for(i=1;i<=n;i++) printf("%s%s", rand() < 0.5 ? "B" : "C", s[i]);
print ""
'
CBXXCCYYBB
answered 6 hours ago
steeldriversteeldriver
40k4 gold badges54 silver badges93 bronze badges
40k4 gold badges54 silver badges93 bronze badges
add a comment |
add a comment |
Anthony D is a new contributor. Be nice, and check out our Code of Conduct.
Anthony D is a new contributor. Be nice, and check out our Code of Conduct.
Anthony D is a new contributor. Be nice, and check out our Code of Conduct.
Anthony D is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f526129%2fusing-sed-to-replace-a-with-a-b-or-c%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The replacement text in the
s
command insed
is text, not an expression.– Kusalananda♦
8 hours ago
2
It would be fairly easy to make the replacements alternate between B and C (using conditional branching)
– steeldriver
7 hours ago
Hello. Thank you for reviewing my question. I am going to try to see if I can make this work without using perl based on your suggestions. I am trying write a .sh that I hope anyone would be able to modify. If I have to add perl, it might be a little complicated for potential users.
– Anthony D
5 hours ago