how to use xargs with sed in search pattern how to use xargs with sed in search pattern bash bash

how to use xargs with sed in search pattern


You need to tell xargs what to replace with the -I switch - it doesn't seem to know about the {} automatically, at least in some versions.

echo "pattern" | xargs -I '{}' sed -i 's/{}/replacement/g' file.txt


this works on Linux(tested):

find . -type f -print0 | xargs -0 sed -i 's/str1/str2/g' 


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.