aditya.gupta
aditya.gupta

Reputation: 615

Manipulating xml file with sed

I have my Strings.xml file containing the following code :

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">myurl</string>
<string name="app_name">MyApp</string>
</resources>

I want to manipulate the value of myurl using command line to a given URL by the user.

The command i'm using is

sed s/myurl/http://192.168.1.1:8080/ strings.xml

But it is throwing an error : sed: 1: "s/myurl/http://192.168. ...": bad flag in substitute command: '/'

This is caused by the two slashes (//). Any way to pass the value to the sed command ?

Upvotes: 1

Views: 524

Answers (2)

Dheeresh Singh
Dheeresh Singh

Reputation: 15701

Use \ before all escape symbols.

Upvotes: 0

FatalError
FatalError

Reputation: 54591

You can use other delimiters with sed, like !:

sed 's!myurl!http://192.168.1.1:8080/!' strings.xml

The (ugly) alternative is to escape them:

sed 's/myurl/http:\/\/192.168.1.1:8080\//' strings.xml

Upvotes: 3

Related Questions