开发者

Perform a FIND in DOS FOR loop

I want to perform a FIND command for all the file extension *.LOG in a directory开发者_Python百科. How can I achieve it? The below is what I have so far, but it is not working and I do not know where's the problem.

for /R C:\folder\log %%i IN (*.LOG) DO (
TYPE %%i | find /I /N "ORA-" >> C:\folder\log\Errorfound.log
ECHO %%i
exit
)


You probably want to use

findstr /R /I /N "ORA-" *.log

You could also use

dir /s /b *.log > input.txt

And then use that file as input for your loop

for /f "eol=; tokens=1 delims=|" %%i in (input.txt) do ( ... )

Some remarks

  • your output file is also a .log in the same folder that you're searching in. If you run the program multiple times, the output file will show up in your results and double your # of output lines

  • don't use "type [file] | do_it" if you can just use stdin: "< [file] do_it"


Several people have already given you the answer. To find and filter all Oracle errors into one log, run this command:

C:\> findstr /ir ora- C:\folder\log\*.log >> C:\folder\log\OracleErrors.txt

which also includes the filenames in every line as you asked. If you only want to echo the filenames, run this second command separately:

C:\> findstr /irm ora- C:\folder\log\*.log

So which part of these is "not working" as you so eloquently put it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜