我必须修改批处理文件以读取每天附加日期的日志文件

时间:2015-03-25 00:24:07

标签: batch-file

我必须修改批处理文件以读取每天附加日期的日志文件。

我的要求是我必须读取当前日期的日志并在日志详细信息中找到一些字符串。示例日志文件如下所示。

c:\\> date /t
Tue 03/23/2015

Batch Summary 
------------------------
Total records = 11
Total records with error = 0
Batch filter ended 

c:\\> date /t
Tue 03/24/2015

Batch Summary 
------------------------
Total records = 11
Total records with error = 0
Batch filter ended "

2 个答案:

答案 0 :(得分:0)

你能详细说明你想做什么吗?

如果您正在尝试获取时间戳,则可以执行echo Timestamp[%date%, %time%] >> log.txt。由于您使用的是>>而不是>,因此您可以在日志文件中获取所请求的每个时间戳,而不是每次执行时都覆盖它。

示例输出为Timestamp[2015-03-24, 20:37:31.86]

答案 1 :(得分:0)

@ECHO OFF
REM is there an entry for today?:
find "%date%" sample.log >nul
if %errorlevel% neq 0 goto :notfound

for /f "delims=" %%i in ('find "Total records with error" sample.log') do set tr=%%i
for /f "delims=" %%i in ('find "Batch filter ended" sample.log') do set bf=%%i

echo %tr%
echo %bf%
goto :eof
:notfound
echo sorry, no data for today.