79668467

Date: 2025-06-17 04:34:55
Score: 2
Natty:
Report link

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
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Blacklisted phrase (1): did not work
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Jacky Lee