How to find the number of occurrences of a string in file using windows command line?

前端 未结 9 1498
生来不讨喜
生来不讨喜 2021-01-01 23:35

I have a huge files with e-mail addresses and I would like to count how many of them are in this file. How can I do that using Windows\' command line ?

I have tried

9条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 00:10

    This is how I do it, using an AND condition with FINDSTR (to count number of errors in a log file):

    SET COUNT=0
    FOR /F "tokens=4*" %%a IN ('TYPE "soapui.log" ^| FINDSTR.exe /I /R^
     /C:"Assertion" ^| FINDSTR.exe /I /R /C:"has status VALID"') DO (
      :: counts number of lines containing both "Assertion" and "has status VALID"
      SET /A COUNT+=1
    )
    SET /A PASSNUM=%COUNT%
    

    NOTE: This counts "number of lines containing string match" rather than "number of total occurrences in file".

提交回复
热议问题