CODE: [Copy to clipboard]
cls
setlocal enabledelayedexpansion
del /f numtodel1.txt
del /f numtodel2.txt
del /f linetodel.txt
del /f sam1.txt
del /f sam2.txt
del /f fileline.txt
:将sam.txt中的空行去掉,生成一个sam1.txt文件
for /f "delims=" %%a in (sam.txt) do echo %%a>>sam1.txt
:标记所有含有stackTrace事件的行号
findstr /i /n /c:stack sam1.txt>linetodel.txt
for /f "delims=:" %%a in (linetodel.txt) do echo %%a>>numtodel1.txt
:根据标记stack的行号X1,X2,X3,X4,生成X1到X2,X3到X4的行号
setlocal enabledelayedexpansion
set begin=
set now=
set end=
set begin=shit
for /f %%a in (numtodel1.txt) do (
set now=%%a
echo %%a !now!
if #!begin!#==#shit# (
set begin=!now!
echo now begin=!begin!
) else (
set end=!now!
echo now begin=!begin! end=!end!
for /l %%a in (!begin!,1,!end!) do echo #%%a#>>numtodel2.txt
set begin=shit
)
)
:得到sam1文件的行数
findstr /n /c:^> sam1.txt>filelines.txt
for /f "delims=:" %%a in (filelines.txt) do set maxline=%%a
echo 最大行数 %maxline%
:读取sam1.txt每一行,并且在numtodel2.txt中搜索该行的号码
:如果找到的,说明该行不需要读取,没有就转向输出到sam2.txt
set num=0
for /f "delims=" %%i in (sam1.txt) do (
set /a num+=1
set str=%%i
findstr /c:#!num!# numtodel2.txt>nul 2>nul
if !errorlevel! neq 0 echo !str!>>sam2.txt
if !num! gtr !maxline! goto end
)
)
:end
:至此文件中所有包含stack的段都去掉了
:去掉每行末尾的/之后的字符
for /f "delims=^/" %%a in (sam2.txt) do echo %%a >>sam3.txt
:暂时就写到这里了,剩下的用for /f处理吧
CODE: [Copy to clipboard]
@echo off&setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (a.log) do (
set a=%%a&set "a=!a:<=|!"&set "a=!a:>=|!"
if "!a:~0,1!"=="|" if not "!a:~1,10!"=="stackTrace" (
for /f "tokens=1-3 delims=|" %%b in ("!a!") do (
set b=%%b&set c=%%c&set d=%%d&echo.Example – parsing a ^<!d:~1!^> node
set c=%%c&set d="!d:~1!"&call:d !d!
echo.%%a&echo.Parses to:&echo.EventType = !d!
if "!b:~10,1!"=="=" echo.EventDescription = !b:~12,-1!
if "!c:~0,1!"=="2" (echo.EventTime = !c!) else echo.EventDescription = !c!
echo.)))>>b.log
pause&exit
:d
set d=%~1
:e
if not "!d:~%n%,1!"=="" set/a n+=1&goto e
set/a n=%n%-1
for %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
for /l %%j in (0,1,%n%) do if "%%i"=="!d:~%%j,1!" set d=!d:~0,%%j!&goto :eof)