Leticia Esperon Leticia Esperon - 1 year ago 73
Ruby Question

Is is possible to create a string in ruby that keeps escaping characters?

I need to form a user-data script from Ruby so I need all escaping characters to remain. When I do this:

def user_data
sed -i -e '/<Name>loadbalanceServerIP<\/Name>/,/<Value>/s/<Value>[^<]*/<Value>' /home/wowza/conf/Server.xml"

The string removes the \ in the Name tag. If I put two \, it keeps them both. Any suggestion as how to keep the string the same way I wrote it?

Thank you!

Answer Source

You can use the %q delimiter rather than ":

def user_data
     sed -i -e '/<Name>loadbalanceServerIP<\/Name>/,/<Value>/s/<Value>[^<]*/<Value>' /home/wowza/conf/Server.xml]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download