Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've searched for this and haven't found it, maybe I'm not using the right terms. I'm looking for a file search utility in Windows 7 that will:

  • search for files in specific directories
  • search for file contents
  • preview found lines (preferably with a couple of lines around the found line)
  • save search terms as presets (like *.aspx.cs or *.cs or a combination of the two)
  • search in office documents

Notepad++ will do this but I'm looking for something that also adds indexing so it's faster. Locate32 does most of it, but doesn't have a preview. Seems that all of the file search utilities that I've found don't do what I want.

share|improve this question
add comment

1 Answer

Well, since you are windows 7, you could do this in powershell. First you would open a Powershell console, then here are some sample commands that you could run (you can see all these examples and more by typing "Get-Help Select-String -example" at the powershell command line):

C:\PS>select-string -path *.xml -pattern "the the"

Description

This command searches through all files with the .xml file name extension in the current directory and displays the lines in those files that include the string "the the".


C:\PS>select-string -path $pshome\en-US\*.txt -pattern "@"

Description

This command searches the Windows PowerShell conceptual Help files (about_*.txt) for information about the use of the at sign (@).

To indicate the path, this command uses the value of the $pshome automatic variable, which stores the path to the Windows PowerShell installa tion directory. In this example, the command searches the en-US subdirectory, which contains the English (US) language Help files for Windows PowerShell.


C:\PS>get-childitem c:\windows\system32\* -include *.txt -recurse |
select-string -pattern "Microsoft" -casesensitive

Description

This command examines all files in the subdirectories of C:\Windows\System32 with the .txt file name extension and searches for the string "M icrosoft". The CaseSensitive parameter indicates that the "M" in "Microsoft" must be capitalized and that the rest of the characters must be lowercase for Select-String to find a match.


C:\PS>$f = select-string -path audit.log -pattern "logon failed" -context 2, 3
C:\PS> $f.count
C:\PS> ($f)[0].context | format-list

Description

The first command searches the Audit.Log file for the phrase "logon failed." It uses the Context parameter to capture 2 lines before the matc h and 3 lines after the match.

The second command uses the Count property of object arrays to display the number of matches found, in this case, 2.

The third command displays the lines stored in the Context property of the first MatchInfo object. It uses array notation to indicate the fir st match (match 0 in a zero-based array), and it uses the Format-List cmdlet to display the value of the Context property as a list.

The output consists of two MatchInfo objects, one for each match detected. The context lines are stored in the Context property of the MatchI nfo object.

share|improve this answer
    
I suppose I could go this direction, but it seems like I'm likely reinventing the wheel this way. I'd rather download a tool -- if such a thing exists that does what I want and does it well. –  jcollum Apr 5 '12 at 18:35
    
@jcollum i suppose a tool would be nicer, but i just want to point out regarding the reinventing the wheel point, you're not 'cos when you get something that tricky, you have it in a script then it's like using a pre-written tool, just that you have the code for it. also, see this link superuser.com/questions/25092/… –  barlop Apr 5 '12 at 19:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.