在文件中查找和显示&QUOT字符串的出现;文件名 - 计数"通过批处理文件 [英] Find occurrences of a string in files and display "filename - count" through batch file

查看:304
本文介绍了在文件中查找和显示&QUOT字符串的出现;文件名 - 计数"通过批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

批处理文件中搜索每一个子文件夹,目录内的每一个文件和计数的次数特定字符串是在每个文件present

Batch file to search every single subfolder and every single file inside a directory and count the number of times a particular string is present in each file.

如果输出将是有益的。文件名 - 伯爵

Would be useful if output is "filename - count".

可以做查找/ C微软的* .txt
 这适用所有的文件存放在一个文件夹中。

Can do find /c "Microsoft" *.txt This works if all the files are in one folder.

你如何查找遍历所有子文件夹和它的每一个文件,并显示了同样的结果。

How do you make the find loop through all the subfolders and each of its files and display the same result.

Findstr工具有哪些呢/ s的是,在发现不工作。

Findstr has /s which does that, doesnt work on find.

推荐答案

从命令行:

for /F "delims=" %G in ('findstr /I /S /M "Microsoft" "%CD%\*.txt"') do @find /I /C "Microsoft" "%~G" | findstr /V /R "^$"

从一个批处理脚本:

From a batch script:

set "_srch=Microsoft"
for /F "delims=" %%G in ('
       findstr /I /S /M "%_srch%" "%CD%\*.txt"') do (
    find /I /C "%_srch%" "%%~G" | findstr /V /R "^$"
)

省略%CD%\\ 你会得到相对路径。

要摆脱 ---------- 找到输出(命令行)

To get rid of ---------- from find output (command line):

for /F "delims=" %G in ('findstr /I /S /M "Microsoft" "%CD%\*.txt"') do @for /F "tokens=1,*" %H in ('find /I /C "Microsoft" "%~G"') do @echo %I

资源:???键入为/ 查找/ FINDSTR / 设置/?或转到的AZ Windows的CMD命令行的索引。

这篇关于在文件中查找和显示&QUOT字符串的出现;文件名 - 计数"通过批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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