SyntaxFix
Write A Post
Hire A Developer
Questions
sed is a stream editor. It searches and replaces greedily. The only way to do what you asked for is using an intermediate substitution pattern and changing it back in the end.
sed
echo 'abcd' | sed -e 's/ab/xy/;s/cd/ab/;s/xy/cd/'