2

I have two files:

1.txt:

abc
def

2.txt:

abc

Please note that 2.txt contains only 3 characters, no empty lines. Now if I do:

findstr /S /I /L /A:02 "abc" *

I get this result:

1.txt:abc
2.txt:abc

Which is what I expect. However after renaming 1.txt to uno.txt and 2.txt to duo.txt (thus changing file search order) and running the same command I get this:

duo.txt:abcuno.txt:abc

Result is in one line and I was expecting two lines as before. Of course if I add new line at the end of duo.txt then output is ok but how to do that without modifing files? Is there some "force result in new line" option in findstr?

user1723095
  • 1,181
  • 1
  • 13
  • 24
  • There is no option to do what you are looking for. Can you explain a little more what you want to do with the results? Maybe there is another way to achieve it. – aphoria May 01 '15 at 17:18
  • I don't have special usecase yet. I just wanted to pipe results to other function like grep but since findstr doesn't work as I expected I think I'll have to use e.g. awk to make it work as I want. Anyway thanks for response. – user1723095 May 01 '15 at 17:27

1 Answers1

2

You could try using a FOR loop to go through the files and pipe the contents of each to FINDSTR.

Something like this:

@ECHO OFF

FOR /R %%f IN (*.txt) DO (
  TYPE %%f | FINDSTR /S /I /L "abc"
)
aphoria
  • 19,796
  • 7
  • 64
  • 73
  • I'll accept this answer since it gives "a way" to do what I wanted but it doesn't do that. For example it doesn't add colored filename before matches. Anyway thanks – user1723095 May 01 '15 at 17:50
  • Thanks for accepting my answer. It definitely seems like a bug in `FINDSTR`. Check out [What are the undocumented features and limitations of the Windows FINDSTR command?](http://stackoverflow.com/questions/8844868/what-are-the-undocumented-features-and-limitations-of-the-windows-findstr-comman) for a thorough documentation of FINDSTR problems and workarounds. – aphoria May 01 '15 at 17:56