I have an xml file where the format looks like below
<SESSIONCOMPONENT REFOBJECTNAME ="pre_session_command" REUSABLE ="NO" TYPE ="Pre-session command">
<TASK DESCRIPTION ="" NAME ="pre_session_command" REUSABLE ="NO" TYPE ="Command" VERSIONNUMBER ="1">
<ATTRIBUTE NAME ="Recovery Strategy" VALUE ="Fail task and continue workflow"/>
<VALUEPAIR EXECORDER ="1" NAME ="Command1" REVERSEASSIGNMENT ="NO" VALUE ="NO"/>
</TASK>
</SESSIONCOMPONENT>
<SESSIONCOMPONENT REFOBJECTNAME ="post_session_success_command" REUSABLE ="NO" TYPE ="Post-session success command">
<TASK DESCRIPTION ="" NAME ="post_session_success_command" REUSABLE ="NO" TYPE ="Command" VERSIONNUMBER ="1">
<ATTRIBUTE NAME ="Fail task if any command fails" VALUE ="NO"/>
<ATTRIBUTE NAME ="Recovery Strategy" VALUE ="Fail task and continue workflow"/>
<VALUEPAIR EXECORDER ="1" NAME ="Command1" REVERSEASSIGNMENT ="NO" VALUE ="NO"/>
</TASK>
The ask is to replace the VALUE tag with the following strings that i will generate on the fly
<SESSIONCOMPONENT REFOBJECTNAME ="pre_session_command" REUSABLE ="NO" TYPE ="Pre-session command">
<TASK DESCRIPTION ="" NAME ="pre_session_command" REUSABLE ="NO" TYPE ="Command" VERSIONNUMBER ="1">
<ATTRIBUTE NAME ="Recovery Strategy" VALUE ="Fail task and continue workflow"/>
<VALUEPAIR EXECORDER ="1" NAME ="Command1" REVERSEASSIGNMENT ="NO" VALUE ="/scripts/waitForDummyFilePDS.sh -f$Paramdummyfile -H$ParamIP -e$Paramemail -j$Paramprefilename"/>
</TASK>
</SESSIONCOMPONENT>
<SESSIONCOMPONENT REFOBJECTNAME ="post_session_success_command" REUSABLE ="NO" TYPE ="Post-session success command">
<TASK DESCRIPTION ="" NAME ="post_session_success_command" REUSABLE ="NO" TYPE ="Command" VERSIONNUMBER ="1">
<ATTRIBUTE NAME ="Fail task if any command fails" VALUE ="NO"/>
<ATTRIBUTE NAME ="Recovery Strategy" VALUE ="Fail task and continue workflow"/>
<VALUEPAIR EXECORDER ="1" NAME ="Command1" REVERSEASSIGNMENT ="NO" VALUE ="scripts/waitForDummyFilePDS.sh -f$Paramdummyfile -H$ParamIP -e$Paramemail -j$Parampostfilename"/>
</TASK>
Im trying to use awk but unable to find the correct use of gsub in this .. any help wil be appreciated
Not sure how you want to substitute the string VALUE with multiple strings as it is present in many places, following is the example of using one variable and doing substitution with VALUE string.
The STR1 should be substituted where the SESSIONCOMPONENT REFOBJECTNAME ="pre_session_command
<SESSIONCOMPONENT REFOBJECTNAME ="pre_session_command" REUSABLE ="NO" TYPE ="Pre-session command">
<TASK DESCRIPTION ="" NAME ="pre_session_command" REUSABLE ="NO" TYPE ="Command" VERSIONNUMBER ="1">
<ATTRIBUTE NAME ="Recovery Strategy" VALUE ="Fail task and continue workflow"/>
<VALUEPAIR EXECORDER ="1" NAME ="Command1" REVERSEASSIGNMENT ="NO" VALUE ="STR1"/>
</TASK>
</SESSIONCOMPONENT>
and STR2 should substitute where SESSIONCOMPONENT REFOBJECTNAME ="post_session_success_command"
<SESSIONCOMPONENT REFOBJECTNAME ="post_session_success_command" REUSABLE ="NO" TYPE ="Post-session success command">
<TASK DESCRIPTION ="" NAME ="post_session_success_command" REUSABLE ="NO" TYPE ="Command" VERSIONNUMBER ="1">
<ATTRIBUTE NAME ="Fail task if any command fails" VALUE ="NO"/>
<ATTRIBUTE NAME ="Recovery Strategy" VALUE ="Fail task and continue workflow"/>
<VALUEPAIR EXECORDER ="1" NAME ="Command1" REVERSEASSIGNMENT ="NO" VALUE ="STR2"/>
</TASK>
</SESSIONCOMPONENT>
just stating the initial value would be "NO" instead of "null" in VALUE
<SESSIONCOMPONENT REFOBJECTNAME ="pre_session_command" REUSABLE ="NO" TYPE ="Pre-session command">
<TASK DESCRIPTION ="" NAME ="pre_session_command" REUSABLE ="NO" TYPE ="Command" VERSIONNUMBER ="1">
<ATTRIBUTE NAME ="Recovery Strategy" VALUE ="Fail task and continue workflow"/>
<VALUEPAIR EXECORDER ="1" NAME ="Command1" REVERSEASSIGNMENT ="NO" VALUE ="/scripts/waitForDummyFilePDS.sh -f$Paramdummyfile -H$ParamIP -e$Paramemail -j$Paramprefilename"/>
</TASK>
</SESSIONCOMPONENT>
<SESSIONCOMPONENT REFOBJECTNAME ="post_session_success_command" REUSABLE ="NO" TYPE ="Post-session success command">
<TASK DESCRIPTION ="" NAME ="post_session_success_command" REUSABLE ="NO" TYPE ="Command" VERSIONNUMBER ="1">
<ATTRIBUTE NAME ="Fail task if any command fails" VALUE ="NO"/>
<ATTRIBUTE NAME ="Recovery Strategy" VALUE ="Fail task and continue workflow"/>
<VALUEPAIR EXECORDER ="1" NAME ="Command1" REVERSEASSIGNMENT ="NO" VALUE ="scripts/waitForDummyFilePDS.sh -f$Paramdummyfile -H$ParamIP -e$Paramemail -j$Parampostfilename"/>
</TASK>
You keep adding new requirements with every post. It would really have been nice to have a complete specification up front.
If I understand correctly, the SESSIONCOMPONENT tag's REFOBJECTNAME parameter can have two values( pre_session_command or post_session_command ). And, if one of those values is found AND a VALUE parameter in a VALUEPAIR tag has the value NO before a /SESSIONCOMPONENT tag is found, then the string NO should be replaced by the contents of the variable STR1 on pre-session entries and by the contents of the variable STR2 on post-session entries. (Note that post #6 in this thread says that the NO should be replaced by one of the literal strings STR1 or STR2 rather than the contents of variables with those names???) Is this correct?
If the value of the VALUE parameter is something other than NO , should any substitution be made?
Are there other values for the REFOBJECTNAME parameter? If so, should these entries be deleted from the output? Copied to the output unchanged? Have some other value assigned to the corresponding VALUE parameter? Something else???
Apologies for the changes made . Don you have posted almost everything correctly
Note that post #6 in this thread says that the NO should be replaced by one of the literal strings STR1 or STR2 rather than the contents of variables with those names???) Is this correct?
The contents of STR1 and STR2 should
In case any value is found in VALUE for eg
VALUE="NO"
or or value like VALUE="/scripts/abc.sh -H$PmRep -N$PmLog" then replace
VALUE="STR1" where SESSIONCOMPONENT REFOBJECTNAME ="pre_session_command
&
VALUE="STR2" where
SESSIONCOMPONENT REFOBJECTNAME ="post_session_success_command
In case no value is found eg
VALUE=""
then substitute
VALUE="STR1" where SESSIONCOMPONENT REFOBJECTNAME ="pre_session_command
&
VALUE="STR2" where
SESSIONCOMPONENT REFOBJECTNAME ="post_session_success_command