how to use xargs with sed in search pattern

前端 未结 4 1529
再見小時候
再見小時候 2020-12-29 06:36

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          


        
4条回答
  •  死守一世寂寞
    2020-12-29 07:34

    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.

提交回复
热议问题