I need to use the output of a command as a search pattern in sed. I will make an example using echo, but assume that can be a more complicated command:
echo
Use command substitution instead, so your example would look like:
sed -i "s/$(echo "some pattern")/replacement/g" file.txt
The double quotes allow for the command substitution to work while preventing spaces from being split.