Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 在动态日志文件中搜索字符串_Batch File - Fatal编程技术网

Batch file 在动态日志文件中搜索字符串

Batch file 在动态日志文件中搜索字符串,batch-file,Batch File,我想为以下内容编写windows批处理脚本 我在路径C:\test\下有一些日志文件,它们每天都在创建,名字中有当天的日期。i、 e u_ex130828.log (created on 28/08/2013) u_ex130827.log (created on 28/08/2013) u_ex130826.log (created on 28/08/2013) 我只想在今天创建的所有文件中搜索特定的错误消息。 一旦发现错误消息,立即将包含错误消息的完整行追加到名为O

我想为以下内容编写windows批处理脚本

我在路径
C:\test\
下有一些日志文件,它们每天都在创建,名字中有当天的日期。i、 e

u_ex130828.log     (created on 28/08/2013)
u_ex130827.log     (created on 28/08/2013)
u_ex130826.log     (created on 28/08/2013)
我只想在今天创建的所有文件中搜索特定的错误消息。 一旦发现错误消息,立即将包含错误消息的完整行追加到名为Output.txt的文本文件中,如果未找到错误消息,则不追加Output.txt文件

cd /d C:\inetpub\logs\LogFiles\W3SVC1\
set "today=%date:~-4%%date:~-10,2%%date:~-7,2%"
for %%a in (*%today%.log) do (
    for /f "delims=" %%b in ('findstr /c:"File attached above for last 2 occasions." "%%~a"') do (
        (echo %%~a: %%~b)>>Output.txt
    )
)
根据您的需要修改文件搜索模式
*%today%.log


修改文件搜索模式
*%today%.根据您的需要记录

这应该可以满足您的需要:

@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set "dt=%%a"
set "YY=%dt:~2,2%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"

set "today=%YY%%MM%%DD%"

findstr /i /c:"File attached above for last 2 occasions." "C:\inetpub\logs\LogFiles\W3SVC1\*%today%.log" > "C:\inetpub\logs\LogFiles\W3SVC1\output.txt"

这应该满足您的需要:

@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set "dt=%%a"
set "YY=%dt:~2,2%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"

set "today=%YY%%MM%%DD%"

findstr /i /c:"File attached above for last 2 occasions." "C:\inetpub\logs\LogFiles\W3SVC1\*%today%.log" > "C:\inetpub\logs\LogFiles\W3SVC1\output.txt"

伟大的它起作用了。非常感谢。。!!如果要使用或搜索另一个字符串,则需要在上面进行哪些更改。如果要搜索另一个字符串,请在已存在的字符串之后添加第二个
/c:“string to find”
。太好了。。!。。它起作用了。非常感谢。。!!如果要使用或搜索另一个字符串,则需要在上面进行哪些更改。如果要搜索另一个字符串,请在已存在的字符串之后添加第二个
/c:“string to find”
。非常感谢您的帮助!!:)我要在这里提出一个警告。小文件,这很好。如果您试图搜索大文件(500MB+),可能会降低服务器速度。有像Grep、Hjsplit和其他方法这样的工具。非常感谢您的帮助。…!!::)我要在这里提出一个警告。小文件,这很好。如果您试图搜索大文件(500MB+),可能会降低服务器速度。有像Grep、Hjsplit和其他方法这样的工具。