如何仅更改最后20行而不是所有内容。
@echo off > newfile & setLocal enableDELAYedexpansion
copy /Y E:\LOG.DIR LOG.DIR
set old=INACTIVE
set new=ACTIVE
for /f "tokens=* delims=" %%a in (LOG.DIR) do (
set str=%%a
echo %SOON
set str=!str:%old%=%new%! >> newfile echo !str!
)
答案 0 :(得分:2)
检查出来:
@ECHO OFF &SETLOCAL
copy /Y E:\LOG.DIR LOG.DIR
set "old=INACTIVE"
set "new=ACTIVE"
FOR /f %%a IN ('^<log.DIR find /v /c ""') DO SET /a length=%%a
SET /a length-=20
SETLOCAL ENABLEDELAYEDEXPANSION
<log.DIR (
FOR /l %%a IN (1,1,%length%) DO (
SET "line="
SET /p "line="
ECHO(!line!
))>newfile
ENDLOCAL
for /f "skip=%length% delims=" %%a in (LOG.DIR) do (
set "str=%%a"
SETLOCAL ENABLEDELAYEDEXPANSION
set "str=!str:%old%=%new%!"
>>newfile ECHO(!str!
endlocal
)
获取find
行数减去20,将结果放入skip=
循环中的for /f
。