Batch file cmd日志文件的高级解析
我需要在cmd中解析日志文件(通过使用find或findstr命令),以便获得特定的记录 日志文件示例:Batch file cmd日志文件的高级解析,batch-file,cmd,find,findstr,Batch File,Cmd,Find,Findstr,我需要在cmd中解析日志文件(通过使用find或findstr命令),以便获得特定的记录 日志文件示例: [2017-04-10 10:53:58.597] [info ] [settings ] [ 1052: 1012] paths.ini_store configuration is empty, settings ini store folder to asw::instup::GetDataDirectory. [2017-04-10 10:53:58.597] [info
[2017-04-10 10:53:58.597] [info ] [settings ] [ 1052: 1012] paths.ini_store configuration is empty, settings ini store folder to asw::instup::GetDataDirectory.
[2017-04-10 10:53:58.597] [info ] [crashguard ] [ 1052: 1012] CrashGuard global exception handler installed
[2017-04-10 10:53:58.738] [debug ] [lim_base ] [ 1052: 3560] Alpha's version:'1
[2017-04-10 10:53:58.738] [info ] [lim_base ] [ 1052: 3560] Alpha settings - enabled:'1'
[2017-04-10 10:54:35.118] [debug ] [lim_av ] [ 1052: 4960] ALPHA PROTO:
'walletKey: "XXXXX-YYYYY-ZZZZZZ"
'
[2017-04-10 10:54:35.196] [debug ] [aswlog ] [ 1052: 4524] c:\windows\system32\fundisc.dll
[2017-04-10 10:54:35.212] [info ] [lim_av ] [ 1052: 4960] IQS - response
[2017-04-10 10:54:35.227] [debug ] [aswlog ] [ 1052: 4524] c:\windows\system32\fvecerts.dll
[2017-04-10 10:54:35.227] [debug ] [lim_burg ] [ 1052: 4960] IqsInfo
[2017-04-10 10:54:35.227] [debug ] [lim_burg ] [ 1052: 4960] ALPHA PROTO:
'token: "ea0989e5-acdc-4cf6-ba1c-e9bdad98b7ce"
wallet_key: "XXXXX-YYYYY-ZZZZZZ"
data: SOME_DATA
success: true
'
[2017-04-10 10:56:05.986] [debug ] [settings ] [ 1052: 2444] Property 'avdef://config/Custody/Enabled' has no entry in defaults map.
[2017-04-10 10:56:06.018] [debug ] [settings ] [ 1052: 2444] Property 'avdef://config/Custody/Enabled' has no entry in defaults map.
输出(控制台或文件输出)中需要的内容如下:
@echo off > newfile & setLocal enableDELAYedeXpansioN
set H=
set T=
for /f "tokens=1* delims=" %%a IN ('find /n /i "PROTO:" service.log') do (
echo.%%a
set H=%%a
for /f "tokens=1* delims=" %%a in ('find /n /i "'" service.log') do (
set T=%%a
)
for /f "tokens=1* delims= " %%a in ('find /n /v "[2017" service.log') do (
if %%a gtr !H! if %%a lss !T! echo.%%b
)
)
PROTO:
”和从[2017]开始的下一条记录开始之间的部分。
[2017-04-10 10:53:58.738] [debug ] [lim_base ] [ 1052: 3560] Alpha's version:'1
[2017-04-10 10:53:58.738] [info ] [lim_base ] [ 1052: 3560] Alpha settings - enabled:'1'
[2017-04-10 10:54:35.118] [debug ] [lim_av ] [ 1052: 4960] ALPHA PROTO:
'walletKey: "XXXXX-YYYYY-ZZZZZZ"
'
[2017-04-10 10:54:35.212] [info ] [lim_av ] [ 1052: 4960] IQS - response
[2017-04-10 10:54:35.227] [debug ] [lim_burg ] [ 1052: 4960] IqsInfo
[2017-04-10 10:54:35.227] [debug ] [lim_burg ] [ 1052: 4960] ALPHA PROTO:
'token: "ea0989e5-acdc-4cf6-ba1c-e9bdad98b7ce"
wallet_key: "XXXXX-YYYYY-ZZZZZZ"
data: SOME_DATA
success: true
'
我在谷歌上搜索和调整的内容如下:
@echo off > newfile & setLocal enableDELAYedeXpansioN
set H=
set T=
for /f "tokens=1* delims=" %%a IN ('find /n /i "PROTO:" service.log') do (
echo.%%a
set H=%%a
for /f "tokens=1* delims=" %%a in ('find /n /i "'" service.log') do (
set T=%%a
)
for /f "tokens=1* delims= " %%a in ('find /n /v "[2017" service.log') do (
if %%a gtr !H! if %%a lss !T! echo.%%b
)
)
但它不能满足我的需要,我将感谢您的帮助。谢谢!@echo off
@echo off
setlocal
rem Reading from input file, call :processFile subroutine and create output file
call :processFile < service.log > newfile.txt
goto :EOF
:processFile
rem Read lines until find "[lim" string
set /P "line="
if errorlevel 1 exit /B
:checkLine
if "%line:[lim=%" equ "%line%" goto processFile
rem Output this line
echo %line%
rem Check if this line have "PROTO:" string
if "%line:PROTO:=%" equ "%line%" goto processFile
rem Output next lines until find "[2017" string at beginning
:nextLine
set /P "line="
if errorlevel 1 exit /B
if "%line:~0,5%" equ "[2017" goto checkLine
echo %line%
goto nextLine
setlocal
rem读取输入文件,调用:processFile子例程并创建输出文件
调用:processFilenewfile.txt
后藤:EOF
:processFile
rem读取行,直到找到“[lim”字符串
设置/P“行=”
如果错误级别1退出/B
:方格线
如果“%line:[lim=%”eq“%line%”转到进程文件
rem输出此行
回音%行%
rem检查此行是否有“PROTO:”字符串
如果“%line:PROTO:=%”eq“%line%”转到进程文件
rem输出下一行,直到在开始处找到“[2017”字符串
:下一行
设置/P“行=”
如果错误级别1退出/B
如果“%line:~0,5%”equ“[2017”转到检查行
回音%行%
转到下一行
@echo off
setlocal
rem读取输入文件,调用:processFile子例程并创建输出文件
调用:processFilenewfile.txt
后藤:EOF
:processFile
rem读取行,直到找到“[lim”字符串
设置/P“行=”
如果错误级别1退出/B
:方格线
如果“%line:[lim=%”eq“%line%”转到进程文件
rem输出此行
回音%行%
rem检查此行是否有“PROTO:”字符串
如果“%line:PROTO:=%”eq“%line%”转到进程文件
rem输出下一行,直到在开始处找到“[2017”字符串
:下一行
设置/P“行=”
如果错误级别1退出/B
如果“%line:~0,5%”equ“[2017”转到检查行
回音%行%
转到下一行
脚本中什么“不起作用”,到底发生了什么?脚本中什么“不起作用”,到底发生了什么?我对搜索期间用作变量的行的最大长度有另一个问题(set/P“line=“)。当该行超过1024个字符时,它就会失败。有什么方法可以克服此限制吗?我找到了一种方法,可以将该行实际拆分为多行,这样现在它的字符数就不会超过1024个,现在就可以了。我对搜索期间用作变量的行的最大长度有另一个问题(set/P“line=)。当该行超过1024个字符时,它就会失败。有什么方法可以克服此限制吗?我找到了一种方法,可以将该行实际拆分为多行,这样现在它的字符数就不会超过1024个,现在就可以了。