我在批处理文件中尝试了此代码,但无法正常工作。我想从 DefaultGateway.txt 中取出第一行并替换 NewFile.txt 中的第三行 ip 地址。
批处理文件代码:
ipconfig /all | findstr Gateway > "C:\Program Files (x86)\""Wireless Guard\""DefaultGateway.txt"
SetLocal EnableDelayedExpansion
type nul > NewFile.txt
set "Default" =Start Line of Paragraph
set "254"=End Line which is not Included
set Flag=0
for /f "tokens=* delims=" %%a in ('type DefaultGateway.txt') do (
if /i "%StartText%" EQU "%%a" (set Flag=1)
if /i "%EndText%" EQU "%%a" (set Flag=0)
if !Flag! EQU 1 echo %%a >> NewFile.txt
)
默认网关.txt:
Default Gateway . . . . . . . . . : 172.20.128.254
Default Gateway . . . . . . . . . :
Default Gateway . . . . . . . . . :
新文件.txt:
remarks:This document is for Linksys for version v4.30.5, the auto sensing part.
"C:\Program Files (x86)\Wireless Guard\wget" --http-user= --http-password=admin
[this is not a link]http://192.168.1.1/WClientMACList.htm
REM del WClientMACList.txt
REM del arp.txt
REM del Intruder1.txt
copy WClientMACList.htm WClientMACList.txt
del WClientMACList.htm
REM del WL_ActiveTable.asp
REM do ping for 20 seconds
REM ping -n localhos