Search code examples
xmlbashsedxmlstarlet

Replacing a string in a file that contains ${user.home} using sed in Linux


I would like to replace string in file contains ${user.home} using sed in Linux but I'm unable to do it. I tried below options using sed but failed.

The input file:

<property name="dev.home"  value="${user.home}"/>

Tried code to replace ${user.home}:

sed -i "s/$${user.home}/r_str/g" 1.xml
sed -i "s/${user.home}/r_str/g" 1.xml
sed -i "s/\$\{user\.home\}/r_str/g" 1.xml

Actual:

<property name="dev.home"  value="${user.home}"/>

Expected:

<property name="dev.home"  value="/dev"/>

Solution

  • You don't need to escape the curly braces {}

    echo '${user.home}' | sed "s/\${user.home}/lol$/"
    lol$