0

I need to write a .bat or .cmd script that will find all instances of file type .log in the directory it is run from, and for each of those search it for "searchstring", counting how many times it appears. Then I need to rename the file (original name: "[name].log") to "name.log". This is to enable me to get a very quick visual count of the number of errors in a file (which is part of what the log contains).

I've already got the for loop that locates all *.log files, but how do I count instances of a particular string?

2
  • 1
    find /c should help you Commented Aug 2, 2013 at 9:46
  • Your rename requirement doesn't make any sense. Did you mean something like "[name].log" becomes "[name]_[count].log" ? Commented Aug 2, 2013 at 20:28

1 Answer 1

1

try this:

for /f "tokens=2delims=:" %a in ('find /c "string" *.log') do @set /a count+=%a
echo %count%

Code is for shell prompt. For shell file replace %a with %%a.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.