Skip to main content
deleted 47 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 238

So I have a task where by I have to manipulate an XML file through a bash shell script.

Here are the steps:

  • Query XML file for a value.
  • Replace the value of a different element with the new value.

Here is the sample xml:

<context-param>
    <param-name>com.sun.faces.sendPoweredByHeader</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>com.sun.faces.numberOfViewsInSession</param-name>
    <param-value>25</param-value>
  </context-param>
  <context-param>
    <param-name>testing</param-name>
    <param-value>25</param-value>
  </context-param>

I need to update the parm value of <param-value>25</param-value> to <param-value>3</param-value> using a shell script.

Any idea what will be the SED command to update only param value of param name(<param-name>com.sun.faces.numberOfViewsInSession</param-name>)?

i tried with below command,

sed -i 's/<param-value>25<\/param-value>/<param-value>3<\/param-value>/' test.xml

but this command will update all the param-values. i need to update only for com.sun.faces.numberOfViewsInSession

thank you so much in advance for you help.

So I have a task where by I have to manipulate an XML file through a bash shell script.

Here are the steps:

  • Query XML file for a value.
  • Replace the value of a different element with the new value.

Here is the sample xml:

<context-param>
    <param-name>com.sun.faces.sendPoweredByHeader</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>com.sun.faces.numberOfViewsInSession</param-name>
    <param-value>25</param-value>
  </context-param>
  <context-param>
    <param-name>testing</param-name>
    <param-value>25</param-value>
  </context-param>

I need to update the parm value of <param-value>25</param-value> to <param-value>3</param-value> using a shell script.

Any idea what will be the SED command to update only param value of param name(<param-name>com.sun.faces.numberOfViewsInSession</param-name>)?

i tried with below command,

sed -i 's/<param-value>25<\/param-value>/<param-value>3<\/param-value>/' test.xml

but this command will update all the param-values. i need to update only for com.sun.faces.numberOfViewsInSession

thank you so much in advance for you help.

I have a task where by I have to manipulate an XML file through a bash shell script.

Here are the steps:

  • Query XML file for a value.
  • Replace the value of a different element with the new value.

Here is the sample xml:

<context-param>
    <param-name>com.sun.faces.sendPoweredByHeader</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>com.sun.faces.numberOfViewsInSession</param-name>
    <param-value>25</param-value>
  </context-param>
  <context-param>
    <param-name>testing</param-name>
    <param-value>25</param-value>
  </context-param>

I need to update the parm value of <param-value>25</param-value> to <param-value>3</param-value> using a shell script.

Any idea what will be the SED command to update only param value of param name(<param-name>com.sun.faces.numberOfViewsInSession</param-name>)?

i tried with below command,

sed -i 's/<param-value>25<\/param-value>/<param-value>3<\/param-value>/' test.xml

but this command will update all the param-values. i need to update only for com.sun.faces.numberOfViewsInSession

edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265
Source Link

Search and replace specific tag value in XML file with sed command

So I have a task where by I have to manipulate an XML file through a bash shell script.

Here are the steps:

  • Query XML file for a value.
  • Replace the value of a different element with the new value.

Here is the sample xml:

<context-param>
    <param-name>com.sun.faces.sendPoweredByHeader</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>com.sun.faces.numberOfViewsInSession</param-name>
    <param-value>25</param-value>
  </context-param>
  <context-param>
    <param-name>testing</param-name>
    <param-value>25</param-value>
  </context-param>

I need to update the parm value of <param-value>25</param-value> to <param-value>3</param-value> using a shell script.

Any idea what will be the SED command to update only param value of param name(<param-name>com.sun.faces.numberOfViewsInSession</param-name>)?

i tried with below command,

sed -i 's/<param-value>25<\/param-value>/<param-value>3<\/param-value>/' test.xml

but this command will update all the param-values. i need to update only for com.sun.faces.numberOfViewsInSession

thank you so much in advance for you help.