none
Replacing line in an XML with a batch file RRS feed

  • Question

  • Hello

    I want to replace a line in an XML file, when the line contains a specific word.

    In my case the line is: 

    <X-PRE-PROCESS cmd="set" data="local_ip_v4=192.168.2.11" />

     There is a unique search string in this line 'local_ip_v4='.

    I would like to create a batch file, that prompts the user for a new IP address and changes it in several files. I already have this for the hosts file, but I am unable to add a section for this file.

    Does anyone have an idea on how to do it?

    Thanks!

    • Moved by Bill_Stewart Wednesday, December 12, 2018 9:44 PM This is not "scripts on demand"
    Tuesday, September 11, 2018 3:13 PM

All replies

  • You cannot do this in a batch file. Use PowerShell with the XML type.

    [xml]$xml = Get-Content >file>

    Now you can use XML methods to find and replace strings or you can just use text methods to replace a specific well identified string.


    \_(ツ)_/


    • Edited by jrv Tuesday, September 11, 2018 3:19 PM
    Tuesday, September 11, 2018 3:18 PM