如何使用Windows命令行查找文件中字符串的出现次数? [英] How to find the number of occurrences of a string in file using windows command line?

查看:606
本文介绍了如何使用Windows命令行查找文件中字符串的出现次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个巨大的文件与电子邮件地址,我想计算他们有多少在这个文件。我如何使用Windows的命令行?

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 ?

我试过了,但它只打印匹配的线。 (btw:所有电子邮件都包含在一行中)

I have tried this but it just prints the matching lines. (btw : all e-mails are contained in one line)

findstr / c:@mail.txt

推荐答案

使用你所拥有的,你可以通过 find 。我已经看到过这样使用的东西。

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"

c> findstr 命令中没有垃圾字符串。种类的黑客,但它可以为你工作。或者,只需在您关心的字符串上使用 find / c 即可。最后,您提到每行一个地址,因此在这种情况下,上面的工作,但每行多个地址,这会中断。

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.

这篇关于如何使用Windows命令行查找文件中字符串的出现次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆