0

I have been looking round and I'm able to find ways of counting lines in a txt file but is there a way i can count for a specific string of text and then place that value in a log file?

0

1 Answer 1

3

The FIND command with the /C option counts and prints the number of matching lines. Anything that is printed to the screen can be redirected to a log file.

find /c "your string" yourFile >yourLog

The above includes the name of the file in the output. If you want only the count, then use redirection or a pipe

find /c "your string" <yourFile >yourLog

or

type yourFile | find /c "your string" >yourLog

All of the above count the number of lines that contain the string. If the string can appear multiple times in the same line and you want to count the total number of times the string appears in the file, then the solution will be much more complex.

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.