Reputation: 129
In the below code, I want to extract the specific string this is Version
after a certain string, from log file myFile.log
that can be found in subdirectory of the directory using a batch file.
Please help me to extract this specific string this is Version
from multiples log files in multiples directories (this directories have the same content).
I have the log file with the following informations (this is just a part of myFile.log
):
2020-09-18 11:19:27,120 INFO [Tollbox.wizar] (ServerService ) Starting, Thi is Version: 1.02.8 - September 18, 2020, appender 2020-09-18 11:19:27,120 INFO [Tollbox.wizar] (ServerService ) Starting, View360 networks 2020-09-18 11:19:27,120 INFO [Tollbox.wizar] (ServerService ) Starting, Solidworks workgroup 2020-09-18 11:19:27,120 INFO [Tollbox.wizar] (ServerService ) Starting, Compiled(32-bit) - September 18, 2020, appender
Example:
folder1\test\myFile.log folder2\test\myFile.log folder3\test\myFile.log
@echo off > newfile & setLocal enableDELAYedeXpansioN
set C=
set A=
for /f "tokens=1* delims=[]" %%a in ('find /v /n "\\\\\\" ^< C:\folder1\test\myFile.log') do (
echo.%%b|find "this is Version" > nul && if not defined C set C=%%a
)
for /f "tokens=1* delims=[]" %%a in ('find /v /n "\\\\\\" ^< C:\folder1\test\myFile.log') do (
if %%a equ !C! (
set S=%%b
set S=!S:this is Version=!
>> C:\newfile.txt echo.!S!
)
if %%a gtr !C! if %%a lss !A! >> C:\newfile.txt echo.%%b
)
goto :eof
Upvotes: 0
Views: 85
Reputation: 56155
You think much too complicated. Get the correct line, remove the part from the front up to (including) Version:
and get the first token from the rest:
@echo off
setlocal
for /f "tokens=*" %%a in ('find "This is Version:" myfile.log') do set "version=%%a"
for /f %%a in ("%version:*Version: =%") do set "version=%%a"
echo "%version%"
Upvotes: 1