1

Following is an Example XML, I need to replace D74DVP1 in all the places. Please help me ? I could only able to replace the word only in first Node.

<?xml version="1.0"?>
    <Forest>
        <Domain>
            <!-- PartitionType:Application -->
            <Guid>01706323-d9a7-4f8d-90d0-1bfb7c88d1d0</Guid>
            <DNSname>ForestDnsZones.D74DVP1.local</DNSname>
            <NetBiosName></NetBiosName>
            <DcName></DcName>
        </Domain>
        <Domain>
            <!-- PartitionType:Application -->
            <Guid>5aca253d-4f3f-475b-b76e-13cd3c694570</Guid>
            <DNSname>ForestDnsZones.D74DVP1.local</DNSname>
            <NetBiosName></NetBiosName>
            <DcName></DcName>
        </Domain>
        <Domain>
            <!-- ForestRoot -->
            <Guid>87d8593d-fcee-4e75-acb6-67b415f5d4a8</Guid>
            <DNSname>D74DVP1.local</DNSname>
            <NetBiosName>D74DVP1</NetBiosName>
            <DcName></DcName>
        </Domain>
    </Forest>

2 Answers2

2

with replacer.bat

call replacer.bat "C:\Example.xml" "D74DVP1" "SomethingElse"

?

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • Never seen you post this on DosTips or maybe I just missed it. Is this just more of a basic find and replace compared to JREPL and FINDREPL? – Squashman Oct 20 '15 at 12:50
  • @Squashman - Yep , I've never posted this on dostips .It nothing so powerful as JREPL or FINDREPL , but I rarely need all the options they offer. – npocmaka Oct 20 '15 at 13:05
0

You may use a Batch file solution, but it is problematic and slow. You may use a Batch-JScript hybrid script like JREPL.BAT or FindRepl.bat instead, that run much faster and have the benefits of regular expressions, but it seems too much just to achieve a simple replace in one file. Fortunately, you may also use the same approach of this solution: write a small Batch-JScript hybrid script specifically developed to solve just this problem. Here it is:

@set @a=0  /*
@cscript //nologo //E:JScript "%~F0" < Example.xml > Example.new
@goto :EOF */

WScript.Stdout.Write(WScript.StdIn.ReadAll().replace(/D74DVP1/g,"SomethingElse"));

For further details on what those strange @lines means, see this post. For a detailed explanation of JScript regular expressions, see here.

PS - Perhaps you forgot the "g" (general) option in the regexp of your VBScript (unposted) code?

Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108