Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何在文本文件中查找字符串并在Windows批处理文件中打印匹配项?_Batch File_Batch Processing - Fatal编程技术网

Batch file 如何在文本文件中查找字符串并在Windows批处理文件中打印匹配项?

Batch file 如何在文本文件中查找字符串并在Windows批处理文件中打印匹配项?,batch-file,batch-processing,Batch File,Batch Processing,有没有办法在几千个文本文件中搜索已定义的字符串并打印匹配文件的名称?不确定要回答哪个操作系统平台 但是Linux/Unix系统可以为此使用以下命令 find . -name '*.ext' -type f | xargs fgrep 'pattern to be searched' 这将从当前目录开始搜索文件,并检查“要搜索的模式”。带有通配符的文件名模式可以应用于我使用“*.ext”的地方 findstr /M "searched string" *.txt > matchingFil

有没有办法在几千个文本文件中搜索已定义的字符串并打印匹配文件的名称?

不确定要回答哪个操作系统平台

但是Linux/Unix系统可以为此使用以下命令

find . -name '*.ext' -type f | xargs fgrep 'pattern to be searched'
这将从当前目录开始搜索文件,并检查“要搜索的模式”。带有通配符的文件名模式可以应用于我使用“*.ext”的地方

findstr /M "searched string" *.txt > matchingFiles.out
findstr/?
文档:

/M         Prints only the filename if a file contains a match.

哦,对不起,我真的忘了提我的操作系统了。这是Windows 7:/不过还是要感谢您的回答:)好的。链接中提到了一个powershell选项(略为相反)。这不是批处理,但您可以尝试记事本++中的“在文件中查找”菜单。这非常有效