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 "some pattern" | xargs sed -i 's/{}/replacement/g' file.txt
That command doesn’t work because “some pattern” has a whitespace, but I think that clearly illustrate my problem.
How can I make that command work?
Thanks in advance,
Use command substitution instead, so your example would look like:
The double quotes allow for the command substitution to work while preventing spaces from being split.