0

I have below entry in web.xml

<context-param>
  <param-name>oracle.adf.view.rich.automation.ENABLED</param-name>
  <param-value>false</param-value>
</context-param>

I am doing some repackaging work using shell script and want to change the value from 'false' to 'true' only for the given param-name. How can I do it using sed/awk command? Note that there are multiple param-name and param-value entries with 'false' values which shouldn't change alongwith.

dganesh2002
  • 1,917
  • 1
  • 26
  • 29

3 Answers3

1
awk -v tgt='oracle.adf.view.rich.automation.ENABLED' '
    found { sub(/false/,"true"); found=0 }
    { found = index($0,"<param-name>" tgt "</param-name>" }
' file
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
  • getting syntax error - awk: found { sub(/false/,"true"); found=0 } { found = index($0,"" tgt "" } ^ syntax error – dganesh2002 Nov 21 '13 at 21:12
  • OK, so fix the syntax error. I'm sure if you put a minutes thought into it you'd see what the problem is. It's just another programming language, it's not magic. – Ed Morton Nov 22 '13 at 00:58
1

Don't parse XML with regex !

Using & (a proper XML parser):

 xmlstarlet edit -L -u "/context-param/param-value" -v 'true' file.xml

To match the Nth element, you can adapt it a bit (starting from 1) :

 xmlstarlet edit -L -u "/context-param[10]/param-value[5]" -v 'true' file.xml
Community
  • 1
  • 1
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
0
sed "/<context-param>/,/<\/context-param>/ {
   /<context-param>/ h
   /<context-param>/ !H
   /<\/context-param>/ {
     x;s/<param-name>oracle.adf.view.rich.automation.ENABLED<\/param-name>/&/
     t chg
     b
:chg
     s/<param-value>false</<param-value>true</
     }" web.xml

treat section context-param, load in buffer, check if param-name is the good one and change false to true if iti is the case

NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43