1

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

user3636391
  • 11
  • 1
  • 2

1 Answers1

3

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
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Thanks for the reply Stephan! I tried the 1st command and it works! but the 2nd one didn't, the error msg prompted was %%i was unexpected at this time, just wondering if I was supposed to substitute the %%i for something? – user3636391 May 15 '14 at 01:08
  • 2
    the double `%%`is for use in a batch file. If you are using it at the command line, use a single `%` – Stephan May 15 '14 at 05:00
  • @Stephan I am facing the same problem of added file name in findstr result even if I am not using wildcards. I am using follwoing command in my batch file - `findstr "TEST" test.dat > output.txt` Could you please help? I want the result without adding file names. – Yash Sep 08 '15 at 17:26
  • `findstr "TEST" test.dat` will never output a filename. (unless to tell you, that `test.dat` doesn't exist or `TEST.ext` as a result of the search) If you use Parameters (for example `/m` or `/s` - that's a different Story. Btw: you may want to [ask a new question](http://stackoverflow.com/questions/ask) with more details. – Stephan Sep 08 '15 at 17:41