我在.bat
文件中包含此脚本,并希望仅在文件末尾保留最近的100行。
如何删除所有其他行?
@echo off
REM *DATETIME2.BAT
REM *Copy date and time to create a new log file
echo.|date>>"\\spserver\myfolder\dt.tmp"
echo.|time>>"\\spserver\myfolder\dt.tmp"
IF NOT EXIST "\\spserver\myfolder\dt.tmp" GOTO Error1
type "\\spserver\myfolder\dt.tmp"|FIND "current">"\\spserver\myfolder\dt.log"
rem del "\\spserver\myfolder\dt.tmp"
GOTO End
:Error1
Echo.
Echo There was an error processing the command.
Echo Unable to find temporary sort file DATETIME2.TMP.
Echo.
GOTO End
:End
答案 0 :(得分:0)
你走了:
Call :Tail 100 dt.log tempout.txt
move /y tempout.txt dt.log>nul
exit /b
:Tail <numlines> <FileIn> <FileOut>
FOR /F "usebackq tokens=3,3 delims= " %%l IN (
`find /c /v "" %2`) DO (call SET find_lc=%%l)
SET /a linenumber=%find_lc%-%1
IF %linenumber% LSS 1 (
more +0 %2 >> %3
) ELSE (
more +%linenumber% %2 >> %3
)