Sanojit
Sanojit

Reputation: 57

How to update the value of particular tag of XML file using shell script

How I pass the arguments to sed command to replace a particular string . I want to replace 8080 with some different port like 8181 or 8282.

grep -rl 8080 /tmp/standalone.xml | xargs sed -i 's/8080/8181/g'

Upvotes: 0

Views: 740

Answers (2)

candymanuu
candymanuu

Reputation: 110

You can sed directly

sed -i "s/$oldValue/$newValue/g" /tmp/standalone.xml

or

sed -i "s/8080/8181/g" /tmp/standalone.xml

Upvotes: 0

Paul Evans
Paul Evans

Reputation: 27577

You want to use double quotes instead of single as variables can then be expanded, something like:

 grep -rl 8080 /tmp/standalone.xml | xargs sed -i "s/8080/$port/g"

Upvotes: 1

Related Questions