下面的批处理文件适用于两个文本文件中的无限服务器列表,并允许port:nnnn
在行中的任何位置包含该选项。它不检查任何错误以使其更简单。
@echo off
setlocal EnableDelayedExpansion
rem Read data from both files
set /P "data1=" < textfile1.txt
set /P "data2=" < textfile2.txt
rem Replace "port" data in all servers
:nextServer
rem Get port number after "port:" in first data and eliminate it
for /F "tokens=1* delims=," %%a in ("%data1:*port:=%") do set port1=%%a& set data1=%%b
rem Replace port number in second data and change colon by semicolon
for /F "tokens=1 delims=," %%a in ("%data2:*port:=%") do set data2=!data2::%%a=;%port1%!
rem Pass to next server, if any
if defined data1 goto nextServer
rem Output result restoring colons
echo %data2:;=:%
例如,使用此数据:
server1.net 2100 /l /n /k port:2000,server2.net 2100 /l /n /k port:20000,server5.net 2100 /l /n /k port:1234
server3.net 2000 /l /k port:xxxx,server4.net 2000 /l /k port:yyyyy,server6.net 2000 /l /k port:zzzz
输出是:
server3.net 2000 /l /k port:2000,server4.net 2000 /l /k port:20000,server6.net 2000 /l /k port:1234