本帖最后由 went 于 2020-11-25 15:30 编辑
start开始,end结束,相邻多个开始结束时间只会保存一个- @echo off & cd /d "%~dp0"
- set "start=15:40:01.098"
- set "end=15:45:45.870"
- del *_NEW.log >nul 2>nul
- for %%i in ("*.log") do call :splitLog "%%i"
- pause&exit
-
- :splitLog
- set "start_line=0"
- for /f "delims=:" %%a in ('findstr /b /r /n /C:"%start%" "%~1"') do set "start_line=%%a"
- set /a "start_line-=1"
- if not "%start_line%"=="-1" (
- (
- for /f "usebackq skip=%start_line% tokens=1*" %%i in ("%~1") do (
- echo %%i %%j
- if "%%i"=="%end%" goto :done
- )
- ) > "%~n1_NEW.log"
- )
- :done
- echo %~1 done.
- echo -------------------------------------
复制代码 保存多个开始结束时间- @echo off & cd /d "%~dp0"
- set "start=15:40:01.098"
- set "end=15:45:45.870"
- del *_NEW.log >nul 2>nul
- for %%i in ("*.log") do call :splitLog "%%i"
- pause&exit
-
- :splitLog
- set "start_line=0"
- for /f "delims=:" %%a in ('findstr /b /r /n /C:"%start%" "%~1"') do set "start_line=%%a" & goto :startDone
- :startDone
- set /a "start_line-=1"
- if not "%start_line%"=="-1" (
- (
- set "enterEnd=0"
- for /f "usebackq skip=%start_line% tokens=1*" %%i in ("%~1") do (
- if not "%%i"=="%end%" (
- call set /a "1/%%enterEnd%%" >nul 2>nul && goto :done || echo %%i %%j
- ) else (
- echo %%i %%j
- if "%%i"=="%end%" set "enterEnd=1"
- )
- )
- ) > "%~n1_NEW.log"
- )
- :done
- echo %~1 done.
- echo -------------------------------------
复制代码
|