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?
1 Answer
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.