writing a special character in sed bash


writing a special character in sed bash



I have a problem, because I want to replace


QueryConnection::DefaultChannel=



with


QueryConnection::DefaultChannel=/${CHANNEL NUMBER}



e.g:
QueryConnection::DefaultChannel=/5



My code:


sed -i "s/QueryConnection::DefaultChannel=.*/QueryConnection::DefaultChannel=${NUMER_KANALU}/" "${DIR_BOTS}/bot_${COUNT_BOTS}/configTS3AudioBot.cfg"



How to make before ${NUMER_KANALU} be "/"?





Possible duplicate of Escape a string for a sed replace pattern, What characters do I need to escape when using sed in a sh script?, etc.
– jww
Jul 3 at 11:49





1 Answer
1



Two choices:



Escape the slash:


sed -i "s/QueryConnection::DefaultChannel=.*/QueryConnection::DefaultChannel=/${NUMER_KANALU}/" "${DIR_BOTS}/bot_${COUNT_BOTS}/configTS3AudioBot.cfg"



Use a different delimiter around the s parameters:


s


sed -i "s#QueryConnection::DefaultChannel=.*#QueryConnection::DefaultChannel=/${NUMER_KANALU}#" "${DIR_BOTS}/bot_${COUNT_BOTS}/configTS3AudioBot.cfg"






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?