07-23-2023, 11:07 AM
I have a series of log files.
I parse these log files with findstr to determine the first instance of a string of text, then return the file name and the line lumber the match was found on as variables.
I then use findstr to parse the file the match was found in for another text string. I return the matching line number as a variable.
I now have the file, the starting and ending line numbers.
I need to return the block of text between my line numbers.
All output is redirected to a textfile represented by the variable casenotes
Here is my code:
:test
echo: >> %casenotes%
echo: test >> %casenotes%
for /f "tokens=1,2* delims=:" %%a in ('findstr /N /C:"Optimize ThreadPools" *_MAGT_*.txt') do set startline=%%b & set filefoundin=%%a & goto part2
:part2
for /f "tokens=1,2* delims=:" %%a in ('findstr /N /C:"After optimization" %filefoundin%') do set endline=%%a & goto part3
:part3
echo: >> %casenotes%
echo: filefound in: %filefoundin% >> %casenotes%
echo: startline is: %startline% >> %casenotes%
echo: endline is: %endline% >> %casenotes%
echo: >> %casenotes%
echo: now do something magic to read everything between lines %startline% and %endline% from %filefoundin% and redirect that output to %casenotes%
Any advice appreciated!
I parse these log files with findstr to determine the first instance of a string of text, then return the file name and the line lumber the match was found on as variables.
I then use findstr to parse the file the match was found in for another text string. I return the matching line number as a variable.
I now have the file, the starting and ending line numbers.
I need to return the block of text between my line numbers.
All output is redirected to a textfile represented by the variable casenotes
Here is my code:
:test
echo: >> %casenotes%
echo: test >> %casenotes%
for /f "tokens=1,2* delims=:" %%a in ('findstr /N /C:"Optimize ThreadPools" *_MAGT_*.txt') do set startline=%%b & set filefoundin=%%a & goto part2
:part2
for /f "tokens=1,2* delims=:" %%a in ('findstr /N /C:"After optimization" %filefoundin%') do set endline=%%a & goto part3
:part3
echo: >> %casenotes%
echo: filefound in: %filefoundin% >> %casenotes%
echo: startline is: %startline% >> %casenotes%
echo: endline is: %endline% >> %casenotes%
echo: >> %casenotes%
echo: now do something magic to read everything between lines %startline% and %endline% from %filefoundin% and redirect that output to %casenotes%
Any advice appreciated!