2

When I use grep I get a list of matching results with the full file path for all the child subdirectories.

When i do this with findstr - I don't get the inline results.

My question is: How do I make findstr show the full file path inline?

hawkeye
  • 34,745
  • 30
  • 150
  • 304

2 Answers2

5

Reading FINDSTR Output in the comprehensive List of undocumented features and limitations of FINDSTR by Dave Benham aka dbenham:

... When printed, the fileName will always include any path information provided. Additional path information will be added if the /S option is used. The printed path is always relative to the provided path, or relative to the current directory if none provided.

Hence, provide absolute path. For instance: instead of

findstr /S /M /I /C:"string being searched for" *.txt

use

findstr /S /M /I /C:"string being searched for" "%CD%\*.txt"

Of course, all /S /M /I /C: switches given in the above example are optional:

d:\bat\files>findstr "success" *.txt
netuser.txt:The command completed successfully.
typeperf.txt:The command completed successfully.

d:\bat\files>findstr "success" "%CD%\*.txt"
d:\bat\files\netuser.txt:The command completed successfully.
d:\bat\files\typeperf.txt:The command completed successfully.
Community
  • 1
  • 1
JosefZ
  • 28,460
  • 5
  • 44
  • 83
  • A link to the original quote would be nice, which is where SS64 got the information. Especially since the original post was on StackOverlow - http://stackoverflow.com/q/8844868/1012053. – dbenham May 30 '15 at 21:32
  • Also, I believe the OP wants the file name prefixed before each matching line, which would rule out the `/M` option. – dbenham May 30 '15 at 21:33
  • @dbenham please forgive my dark on the quote origin; see my edit on the `/M` switch as well:) – JosefZ May 31 '15 at 09:31
2
findstr "search string" %cd%\*
hawkeye
  • 34,745
  • 30
  • 150
  • 304