Use groupings echo “abbc” | sed -E -n “s/(ab)(bc)/\2\1/p"
echo “abbc” | sed -E -n “s/(ab)(bc)/\2\1/p"
got it from this