2

I am trying to search for an email address on my harddisk. I know that it should be something like:

b************m@e******.com

and this is why I came up with this regex:

b.{12}m@e.{6}.com

I found that findstr could be useful for this job and tried:

findstr /R b.{12}m@e.{6}\.com c:\*.*

but it doesn't find anything even if I added a file with an email that should match that regex of mine, this one for example: b8726ngs.poinm@e123456.com

Mark Wragg
  • 22,105
  • 7
  • 39
  • 68
asknomore
  • 31
  • 1
  • 5

2 Answers2

0

You could try doing this with the following PowerShell command instead (note depending on where you start this could take a long time to run):

Get-ChildItem *.txt -Recurse -File | Where-Object { (Get-Content $_.FullName) -match "b.{12}m@e.{6}.com" }

You will get red error messages for areas of the disk that you don't have permission to access. Run PowerShell as Administrator for the widest possible search.

Add a file path to Get-ChildItem in order to set a base directory if you wish, otherwise it will start in the directory you are currently in.

Explanation of parameters:

  • -Recurse searches the current directory and all sub-directories.
  • -File returns only files (not directories).
  • Get-Content $_.FullName gets the contents of each file.
  • -match performs the regex comparison.
Mark Wragg
  • 22,105
  • 7
  • 39
  • 68
  • No, it's inside the file! I'm sorry I didn't point this out as I thought it's obvious. So more likely that email address is inside e .txt file but just to make sure I want to find all files – asknomore Apr 24 '17 at 14:52
  • Sorry, I forgot that's what `findstr` so it should have been obvious! I've amended my answer with one that will search in the contents of files. – Mark Wragg Apr 24 '17 at 15:01
  • I have tried your solution and it works just that when I search the root hdd, my CPU goes to 95% and it also the powershell consumes a lot of memory - started building 1.5 Gb in less than 15 minutes so can you please tell me how to only search for *.txt files? – asknomore Apr 24 '17 at 19:53
  • `Get-childitem *.txt -recurse` – Mark Wragg Apr 24 '17 at 19:56
  • Thank you - It's now running and cpu is @ 100% and same for the Memory. Any way I can decrease its usage? – asknomore Apr 24 '17 at 22:18
0

There are regex and then there are regex. Looks like findstr is not very powerful.

findstr /R "b............m@e......\.com" *.*

This is only on the findstr part not working.
Do this with appropriate precautions, e.g. inside a directory which only contains readable files.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • Running this from c:\ it will throw FINDSTR: Cannot open hiberfil.sys FINDSTR: Cannot open pagefile.sys FINDSTR: Cannot open swapfile.sys and then stops so I guess it will not find in all subdirectories. – asknomore Apr 24 '17 at 22:17