Search code examples
linuxsedmakefilespecial-charactersquoting

sed command in make file with hard coded $


I have a sed command in my makefile like following ,purpose of the command is, it should replace string "listen $address" to "",but as a result it is replacing "listen $address" to "$address"

sed -i -e "s/listen $$address//" file.txt

Please suggest any solution. I have checked many posts but there $ is used as regex variable ,in my case it needs to be treated as hardcoded string


Solution

  • Enclose your sed command in single quotes to avoid variable expansion within double quotes:

    sed -e -i 's/listen $address//' file
    

    You can use double quotes though by escaping the $:

    sed -e -i "s/listen \$address//" file