Monday, October 15, 2012

Search all text files by file's content

Finding a text-file, when one doesn't remember the file-name, or where one has stored it on the hard-drive can be a nightmare, especially since the Windows file-search fails. Powershell (udner Windows) comes to the rescue... all you have to do, is open up a Powershell console (in the newer versions it comes with the Windows OS, in older ones, you might need to download it).
  1. Make shure that in the command prompt of powershell you are within the drive you want to search (i.e. use cd and ..cd commands to get there, or type cd c: if you need to search the c drive.
  2. Get-ChildItem -Recurse -Include *.txt | Select-String "search string"
where search string is simply a piece of text that you know is in the contents of the file. For example in my case I type ANOVA, since I was looking for my notes on ANOVA tests. I think you can also use regex expressions, since powershell's Select-String cmd-let supports it, if I'm not mistaken.

No comments:

Post a Comment