findstr或grep输出文件

时间:2021-12-07 03:02:51

Im in Windows Server 2003 and using below commands to fetch string matching lines in files created today in a specific directory.

在Windows Server 2003中的Im,并使用以下命令在特定目录中创建的文件中获取字符串匹配行。

forfiles -p D:\ -m *.1  -d +0 -c "cmd /c findstr /i /c:\"Hey Hi\" @FILE" >> txt5.txt
or
forfiles -p D:\ -m *.1  -d +0 -c "cmd /c grep \"Hey Hi\" @FILE" >> txt5.txt

Geeting error 'FINDSTR: Write error' and 'grep write error bad file descriptor' respectively for both commands. So basically the commands work i.e. display the output in screen but unable to redirect the output to a file.

Geeting error' FINDSTR: Write error'和'grep Write error bad file descriptor'分别用于这两个命令。基本上这些命令都可以工作,比如在屏幕上显示输出,但是不能将输出重定向到文件。

I did not find suitable solution though users reported this same error for different scenarios. Any help is appreciated. Thanks in advance!

我没有找到合适的解决方案,尽管用户在不同的场景中报告了相同的错误。任何帮助都是感激。提前谢谢!

1 个解决方案

#1


1  

You should be able to remove the cmd /c; I don't see any reason you'd need a new copy of the command shell open for the findstr call.

您应该能够删除cmd /c;我看不出有什么理由需要为findstr调用打开命令shell的新副本。

This works for me correctly at the command prompt:

这对我在命令提示符下是正确的:

forfiles -m t*.xml -d +0 -c "findstr /i "Item" @file" >> out.txt. 

It produces an out.txt file that contains the proper content matching the search criteria.

它产生出来。txt文件,包含匹配搜索条件的适当内容。

#1


1  

You should be able to remove the cmd /c; I don't see any reason you'd need a new copy of the command shell open for the findstr call.

您应该能够删除cmd /c;我看不出有什么理由需要为findstr调用打开命令shell的新副本。

This works for me correctly at the command prompt:

这对我在命令提示符下是正确的:

forfiles -m t*.xml -d +0 -c "findstr /i "Item" @file" >> out.txt. 

It produces an out.txt file that contains the proper content matching the search criteria.

它产生出来。txt文件,包含匹配搜索条件的适当内容。