2017-04-18 11 views
1

특정 레코드를 얻으려면 cmd에서 로그 파일을 구문 분석해야합니다 (find 또는 findstr 명령 사용). "[LIM"문자열이 포함 된cmd에 대한 로그 파일의 고급 구문 분석

  1. 전체 기록 : 로그 파일의

    예 : 다음과 같이 I 출력 (콘솔이나 파일 출력)에 가질 필요가 무엇

    [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. 
    

    입니다 (이것은 매우 쉽지만 ..)

  2. 부분이 "PROTO:"이고 다음 레코드 시작 부분이 [2017..
  3. 인 부분에 위치합니다.

그래서 예를 들어 같이 나에게 줘야 위 :

@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 
) 
) 

을하지만 내가 필요로하는 일을하고 나는하지 않습니다 다음과 같이 내가 봤 및 조정 한 무엇

[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 
                   ' 

입니다 당신의 도움에 감사드립니다. 고맙습니다!

+0

스크립트에서 "작동하지 않는"현상은 정확히 어떻게됩니까? – aschipfl

답변

0
@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 
+0

감사합니다 Aacini, 매력처럼 작동합니다! ;-) –

+0

검색 중에 변수로 사용할 줄의 최대 길이에 다른 문제가 있습니다 (set/P "line ="). 줄이 1024자를 넘으면 실패합니다. 이 한계를 극복 할 수있는 방법이 있습니까? –

+0

실제로 줄을 여러 줄로 나누는 방법을 발견 했으므로 지금은 1024자를 초과하지 않으며 이제는 괜찮습니다. –