简体   繁体   中英

Windows batch script to replace a string

I have a txt file that looks like this:

file: config.txt

property name="java.nio.preferSelect" value="true"

property name="pico.rcp.platform.host" value="172.22.3.11"

property name="pico.rcp.platform.port" value="6790"

I want a windows batch script that will search for "pico.rcp.platform.host" string and change the IP value in that line regardless its value to the passed value in the command line. Like the following:

changeServerTo.bat "172.22.3.1" config.txt

the above script should make the file looks like this:

file: config.txt

property name="java.nio.preferSelect" value="true"

property name="pico.rcp.platform.host" value="172.22.3.1"

property name="pico.rcp.platform.port" value="6790"

and

changeServerTo.bat "172.22.100.221" config.txt

should make the file looks like this:

file: config.txt

property name="java.nio.preferSelect" value="true"

property name="pico.rcp.platform.host" value="172.22.100.221"

property name="pico.rcp.platform.port" value="6790"

and so on.

Your help is much appreciated.

Thanks in advance.

This script just rewrites the entire file and uses the parameter in the output

echo property name="java.nio.preferSelect" value="true" >config.txt 
echo property name="pico.rcp.platform.host" value=%1 >>config.txt 
echo property name="pico.rcp.platform.port" value="6790" >>config.txt 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM