Thank you for your example code.
Here is the script modified from yours, but did not work.
@ECHO OFF
SETLOCAL
rem The following settings for the directories and filenames are names
rem that I use for testing and deliberately includes spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET sourcedir=d:\test
SET destdir=d:\test\result
SET filename1=%sourcedir%\sample.log
SET "beginfence=========IPMI Sensor Info Begin========"
SET "endfence=========IPMI Sensor Info End========"
SET /a outfilenum=0
SET "output="
FOR /f "usebackqdelims=" %%y IN (%filename1%) DO (
SET "line=%%y"
CALL :outline
ECHO x%%y|FIND "%endfence%">NUL
IF ERRORLEVEL 1 (
ECHO x%%y|FIND "%beginfence%">NUL
IF NOT ERRORLEVEL 1 (
SET "output=Y"
SET /a outfilenum+=1
CALL :outline
)
) ELSE (
rem endfence found
SET "output="
)
)
GOTO :EOF
:outline
IF DEFINED output >>"%destdir%\filebase_%outfilenum%.log" ECHO %line%
GOTO :eof