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

前端 未结 9 1442
生来不讨喜
生来不讨喜 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:19

    Using what you have, you could pipe the results through a find. I've seen something like this used from time to time.

    findstr /c:"@" mail.txt | find /c /v "GarbageStringDefNotInYourResults"
    

    So you are counting the lines resulting from your findstr command that do not have the garbage string in it. Kind of a hack, but it could work for you. Alternatively, just use the find /c on the string you do care about being there. Lastly, you mentioned one address per line, so in this case the above works, but multiple addresses per line and this breaks.

提交回复
热议问题