首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从文本文件中找到同一个特定的单词,并将其作为输出来表示?

如何从文本文件中找到同一个特定的单词,并将其作为输出来表示?
EN

Stack Overflow用户
提问于 2017-08-26 17:30:05
回答 1查看 393关注 0票数 0

我有一个名为file.txt的文本文件,其中包含

代码语言:javascript
复制
A: - No such Root Directory
B: - No such Root Directory
C: - Fixed Drive
D: - Fixed Drive
E: - Removable Drive
F: - CD-ROM Drive
G: - Removable Drive
H: - No such Root Directory
I: - No such Root Directory
J: - No such Root Directory
K: - No such Root Directory
M: - No such Root Directory
N: - No such Root Directory
O: - No such Root Directory
P: - No such Root Directory
Q: - No such Root Directory
R: - No such Root Directory
S: - No such Root Directory
T: - No such Root Directory
U: - No such Root Directory
V: - No such Root Directory
W: - No such Root Directory
X: - No such Root Directory
Y: - No such Root Directory
Z: - No such Root Directory

在这个文件中,您可以注意到第5行和第7行中出现了两个单词Removable

如果它有相同的特定单词Removable两次或三次,它需要显示输出有Removable word found multiple times

如果它没有相同的特定单词Removable两次或三次,它需要显示输出有There is no multiple Removable word found

对于这个输出,我运行了以下程序,

代码语言:javascript
复制
findstr /b Removable "file.txt" do ( 
echo Removable word found multiple times 
) || ( 
echo There is no multiple Removable word found 
)
pause

我知道这是错误的。但是我已经尽力了。朋友们,请纠正我。这对我会很有帮助的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-26 17:47:00

您应该能够使用Find /I /C "Removable"<"file.txt"来获取该文件中可移动实例的数量。你要做的就是检查那个号码。最常见的方法是通过将该命令放在for循环中读取该值。

就像命令提示符窗口中的这一行:

代码语言:javascript
复制
For /F %A In ('Find /I /C "Removable"^<"file.txt"') Do @If %A Lss 1 (Echo=There is no multiple Removable word found) Else Echo Removable word found %A times
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45898005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档