How to remove filename in findstr output file

泄露秘密 提交于 2019-12-25 06:37:11

问题


I use findstr to search and output my search to another txt file but need to omit the filename, can anyone help pls? Thanks in advance!

My current batch file :- findstr "TEST" *.dat > output.txt

and the result of output.txt with all the filename Doc*.dat(which I need to remove):-

Doc (1).dat:2014-04-15;TEST TECHNOLOGY LTD
Doc (10).dat:2014-04-29;TEST TECHNOLOGY LTD
Doc (11).dat:2014-04-30;TEST TECHNOLOGY LTD
Doc (12).dat:2014-05-02;TEST TECHNOLOGY LTD
Doc (13).dat:2014-05-05;TEST TECHNOLOGY LTD
Doc (14).dat:2014-05-06;TEST TECHNOLOGY LTD

Best Regards, W


回答1:


findstr writes the filename, when you use wildcards.

Alternatives:

use another command, that doesn't write the filename in the same line as the content:

find "TEST" *.dat |find "TEST" >output.txt

or:

use findstr without wildcards (use a forloop to supply one filename at a time)

for %%i in (*.dat) do findstr "TEST" %%i >>output.txt


来源:https://stackoverflow.com/questions/23655237/how-to-remove-filename-in-findstr-output-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!