sed replace single/double quoted text?

后端 未结 4 1258
南旧
南旧 2021-02-04 06:11

Having some difficulty in replacing some single/double quoted text with sed and was wondering what\'s the correct method for these 2 examples

to change

4条回答
  •  野的像风
    2021-02-04 06:31

    You either need to quote the quotes or escape the quotes. Did you try checking what sed sees when you give it that last command?

    sed -i 's/'ADMIN_USERNAME','memcache'/'ADMIN_USERNAME','u'/g' /var/www/html/memcache.php

    Try this:

    echo sed -i 's/'ADMIN_USERNAME','memcache'/'ADMIN_USERNAME','u'/g' /var/www/html/memcache.php

    It gives this:

    sed -i s/ADMIN_USERNAME,memcache/ADMIN_USERNAME,u/g /var/www/html/memcache.php

    Oops! Your single quotes were not interpreted how you thought. An easy workaround for this case is to quote protect your sed command from the shell with double quotes instead.

    sed -i "s/'ADMIN_USERNAME','memcache'/'ADMIN_USERNAME','u'/g" /var/www/html/memcache.php

提交回复
热议问题