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

查看:22
本文介绍了如何使用 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 ?

我已经尝试过了,但它只是打印匹配的行.(顺便说一句:所有电子邮件都包含在一行中)

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"

因此,您正在计算 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天全站免登陆