Batch code to find and replace strings in xml files and move

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Venkat
Posts: 6
Joined: 28 Jun 2014 22:14

Batch code to find and replace strings in xml files and move

#1 Post by Venkat » 28 Jun 2014 22:28

Hi i need a BATCH CODE to find and replace the below two tasks(Task_RunOwt,Task_RunDbdIo) if found with another task(Task_RunGenericIo) in around 1500 xml files..is it possible??? :o :o ::) :-\ The changed files should be moved to different folder after replacing the strings... ???

old tasks to be replaced:
1)

<task>
<uid>1T1I</uid>
<name>Task_RunOwt</name>
<params>
<OrcIp>$ORC1IP$</OrcIp>
<OrcUsername>$ORC1USERNAME$</OrcUsername>
<OrcPassword>$ORC1PASSWORD$</OrcPassword>
<VolumeNames>$VOLUME1NAME$,$VOLUME2NAME$</VolumeNames>
<WriteToRawVolume>true</WriteToRawVolume>
<IoToolOptions>-b512 -n4194304 -o0 -t256 -c1 -r0 -l0 -w100 -s10 -p0 -g1 -v0 -d1 -z'' -q64 -f'' -i'' -u0</IoToolOptions>
</params>
<pass>1T3G</pass>
<fail>abortfail</fail>
<incomplete>abortfail</incomplete>
</task>

2)

<task>
<uid>1T1I</uid>
<name>Task_RunDbdIo</name>
<params>
<OrcIp>$ORC1IP$</OrcIp>
<OrcUsername>$ORC1USERNAME$</OrcUsername>
<OrcPassword>$ORC1PASSWORD$</OrcPassword>
<VolumeNames>$VOLUME1NAME$,$VOLUME2NAME$</VolumeNames>
<IOToolOptions>--queue 64 --seed --io_profile --trace STAT</IOToolOptions>
</params>
<pass>1T3G</pass>
<fail>abortfail</fail>
<incomplete>abortfail</incomplete>
</task>

New Task Which has to be substituted in place of above two tasks if found in the xml files:

<task>
<uid>1T1I</uid>
<name>Task_RunGenericIo</name>
<params>
<GroupName>$GROUP1NAME$</GroupName>
<ClusterName>$CLUSTER1NAME$</ClusterName>
<WriteToRawVolumeOrFile>raw</WriteToRawVolumeOrFile>
<Client>
<OrcIp>$ORC1IP$</OrcIp>
<OrcUsername>$ORC1USERNAME$</OrcUsername>
<OrcPassword>$ORC1PASSWORD$</OrcPassword>
<Volume>
<Names>$VOLUME1NAME$,$VOLUME2NAME$</Names>
</Volume>
</Client>
</params>
<pass>1T3G</pass>
<fail>abortfail</fail>
<incomplete>abortfail</incomplete>
</task>


Points to be noted:

*uid,pass,fail and incomplete tags and its content in the xml code should remain unchanged,only the code in between the uid and pass tags should be replaced with following
*In RunOwt task,When WriteToRawVolume is mentioned true, in RungenericIo,WriteToRawVolumeOrFile should be= raw
*In RunOwt task,When WriteToRawVolume is mentioned false, in RungenericIo,WriteToRawVolumeOrFile should be= file
*When RunDbdio task is found ,in RungenericIo,WriteToRawVolumeOrFile should always be =raw
*if only volume1name exists than only volume1name should be present(but not volume2name).
*IoToolOptions in above tasks is not required in RunGenericIo task.
*basically the xml code logic should be same after replacement
*I dont think any Xml file contains both the tasks Task_RunOwt and Task_RunDbdIo in a single XML File , But even if thats the scenario ,replacement has to be done with Task_RunGenericIo since other two tasks are deprecated.
*Every Xml file has many different tasks which has Task_RunOwt and Task_RunDbdIo repeated no. of times or only once.
*All 1500 xml files are not in single folder,they are in different folders of same directory.
*Task_RunOwt and Task_RunDbdIo tasks are deprecated in the tool i work with, so i need them get replaced with Task_RunGenericIo which is used for writing data in volumes of Client Orcs mentioned..



It would be of great help if this works out...Thanks in advance...


foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch code to find and replace strings in xml files and

#3 Post by foxidrive » 29 Jun 2014 14:08

Can the tasks be removed from the XML files and simply be edited and re-added onto the end of the XML files?

Venkat
Posts: 6
Joined: 28 Jun 2014 22:14

Re: Batch code to find and replace strings in xml files and

#4 Post by Venkat » 29 Jun 2014 21:25

Hi Foxi,
Can the tasks be removed from the XML files and simply be edited and re-added onto the end of the XML files?


The tasks shouldnt be removed from Xml files and even if removed, should be added back in the same place with same Uid since it will affect the execution flow.. :cry: :oops:

Venkat
Posts: 6
Joined: 28 Jun 2014 22:14

Re: Batch code to find and replace strings in xml files and

#5 Post by Venkat » 29 Jun 2014 21:29

Foxi,
Can the tasks be removed from the XML files and simply be edited and re-added onto the end of the XML files?


The tasks shouldnt be removed since it will affect the flow and even if the tasks are removed , they should be added in the same place back again after editing :? :oops:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch code to find and replace strings in xml files and

#6 Post by foxidrive » 30 Jun 2014 05:09

There's no built in tool to edit blocks in the specific ways that your query specifies.

It would be a convoluted batch file to solve all the pieces - but maybe there XML editors around to help here?

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch code to find and replace strings in xml files and

#7 Post by penpen » 01 Jul 2014 02:34

You could use the jscript/batch hybrid xslt to solve this (jscript enabled: default case for most windows systems).

Just use the "xslt.bat" located here (second source block):
http://www.dostips.com/forum/viewtopic.php?p=32941#p32941.

If you want to transform an xml named "input.xml", using an xslt "transform.xsl" to create a new xml named "output.xml"
Then just call this batch using:

Code: Select all

call "xslt.bat" "input.xml" "transform.xsl" "output.xml"

penpen

Venkat
Posts: 6
Joined: 28 Jun 2014 22:14

Re: Batch code to find and replace strings in xml files and

#8 Post by Venkat » 02 Jul 2014 21:45

foxidrive wrote:There's no built in tool to edit blocks in the specific ways that your query specifies.

It would be a convoluted batch file to solve all the pieces - but maybe there XML editors around to help here?


I dont have any idea regarding that foxi..If i get something ll let u know..

Venkat
Posts: 6
Joined: 28 Jun 2014 22:14

Re: Batch code to find and replace strings in xml files and

#9 Post by Venkat » 02 Jul 2014 21:52

penpen wrote:You could use the jscript/batch hybrid xslt to solve this (jscript enabled: default case for most windows systems).

Just use the "xslt.bat" located here (second source block):
http://www.dostips.com/forum/viewtopic.php?p=32941#p32941.

If you want to transform an xml named "input.xml", using an xslt "transform.xsl" to create a new xml named "output.xml"
Then just call this batch using:

Code: Select all

call "xslt.bat" "input.xml" "transform.xsl" "output.xml"

penpen

Thank you, I ll Check it out and let you no if it works :)

Post Reply