When we match a pattern using sed, the matched pattern is stored in the \"ampersand\" (&) variable. IS there a way to replace a character in this matched pattern using the a
This might work for you (GNU sed and Bash):
sed 's/apple1/sed "s|1|2|" <<<"&"/e' file