Sed replacement not working when using variables [duplicate]
something strange is happening when trying to replace string with sed. This works :
find /home/loni/config -type f -exec sed -i 's/some_pattern/replacement/g' {} \;
So it works when I manually type the strings. But in the case below replacement doesn't occur :
find /home/loni/config -type f -exec sed -i 's/${PATTERN}/${REPLACEMENT}/g' {} \;
When I echo these two variables PATTERN and REPLACEMENT they have the correct values. 开发者_开发问答
I'm trying to replace all occurences of pattern string with replacement string in all files in my config directory.
Try
find /home/loni/config -type f -exec sed -i "s/${PATTERN}/${REPLACEMENT}/g" {} \;
instead. The ' quotes don't expand variables.
Not sure if I got this right, but if you want to replace the ${PATTERN} with ${REPLACEMENT} literally you have to escape the dollar and maybe the braces, those are reserved characters in regular expressions:
find /home/loni/config -type f -exec sed -i -e 's/\$\{PATTERN\}/\$\{REPLACEMENT\}/g' {} \;
精彩评论