使用 Batch 查找今天出现的关键字



我需要使用批处理程序在我的日志.txt文件中查找今天发生的所有ORA错误。我不擅长 Batch,因此无法使用下面的代码添加日期时间过滤器。

@echo off
findstr /m "ORA-" Alert.txt
if %errorlevel%==0 (
echo There is an ORA Error in Alert File!
)

文件中的错误:

2019-10-14T00:43:40.497493+01:00
Errors in file C:R2DATABASEPRODUCT12.2.0diagrdbmsr2r2tracer2_j000_11628.trc:
ORA-12012: error on auto execute of job "R2"."R3NOTIFICATION_160328336632"
ORA-06550: line 1, column 763:
PLS-00201: identifier 'R3NOTIFICATION_PKG.GENERATENOTIFICATIONFORR3' must be declared
ORA-06550: line 1, column 763:
PL/SQL: Statement ignored
2019-10-14T00:43:42.029005+01:00
Errors in file C:R2DATABASEPRODUCT12.2.0diagrdbmsr2r2tracer2_j001_2524.trc:
ORA-12012: error on auto execute of job "R2"."R3NOTIFICATION_160328336632"
ORA-06550: line 1, column 763:
PLS-00201: identifier 'R3NOTIFICATION_PKG.GENERATENOTIFICATIONFORR3' must be declared
ORA-06550: line 1, column 763:
PL/SQL: Statement ignored

日期时间格式 -2019-10-14T00:43:40.497493+01:00

这是一个基于Gerhard评论建议的示例。它应该输出今天的行,这些行以ORA-开头,描述以error开头。

@Set "Var="
@For /F "Tokens=1-3Delims=/ " %%A In (
'^""%__APPDIR__%Robocopy.exe" /NJH /L "|" Null^"'
)Do @If Not Defined Var Set "Var=%%A-%%B-%%CT"
@Set "Line="
@For /F "Delims=:" %%A In ('FindStr /NLB "%Var%" "Alert.txt"'
)Do @If Not Defined Line Set /A Line=%%A-1&GoTo :GetLines
:GetLines
@If Defined Line More +%Line% "Alert.txt"|"%__APPDIR__%findstr.exe" /LB "ORA-"
@Pause

最新更新