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.

As the title suggests, what's the fastest (accurate) way of finding which lines of which files match a particular string.

Specifically, I'm searching .cpp and .h files.

share|improve this question

10 Answers 10

up vote 9 down vote accepted

Notepad++ has 'find in files' option, which is located in the 'Search' menu.. This will allow you to search multiple files in a folder (you can specify the folder) and will show you the line numbers of each file as well. You can toggle whether subfolders and hidden folders are included in the search, and it will also allow you to search with \t \n etc. and to search with regular expressions if you need.

Notepad++ is a Windows programmers editor (not an IDE) and is Open Source too.

(i realise that you have most likely heard of notepad++, but I'm just mentioning it here as an option incase you were unaware of this particular feature, and for others who stumble across this thread later on.

Cheers :)

share|improve this answer
    
Yeah, I must admit, I've used Notepad++ for this before. –  Jon Cage Jun 13 '12 at 13:43
1  
@JonCage there's somebody in this thread sevenforums.com/software/… that also speaks like you saying "I admit" when it comes to useful things. That's an extremely odd way of speaking. You might want to meet that person. Maybe your twin. –  barlop Jun 13 '12 at 15:45
    
Notepad++ is great. Other programmer's editors like SciTE have similar functionality as well. –  TimothyAWiseman Jun 18 '12 at 20:55

Agent Ransack works like a charm. Download it here.

share|improve this answer
    
Agent Ransack was the old name, now its called File Locator Lite –  rubber boots Jun 13 '12 at 16:59

Findstr always works for me. It can use text * wildcards or regex for the search string. Findstr /? for more

share|improve this answer

On Unix systems people would most likely use grep to do this, so why not use Windows Grep?

http://www.wingrep.com/

share|improve this answer
    
Windows Grep can sometime become unstable, but it is the fastest searching program I have ever used. –  yakatz Jun 13 '12 at 20:32
    
@yakatz Thanks for mentioning possible instability with Windows Grep, I will look for a different grep/replace tool! –  pacoverflow May 22 at 7:06

Here's a Powershell solution:

gci -r $SomePath -filter "*.cpp","*.h" | Select-String $FindThisString

The -r in gci is for recurse, and of course is optional, as are the two file extension filters. A useful parameter of Select-String is -list which will only report the first instance of a match in a file, instead of giving you each occurrence of it per file.

Perhaps you want to instantly open each file where a match is found? Well, the following small change to the above is quite useful, depending on what you have your default file association as:

gci -r $SomePath -filter "*.cpp","*.h" | Select-String $FindThisString -list | ii

share|improve this answer
    
I was about to post the same thing :) –  Caleb Jares Jun 13 '12 at 21:14

while doing a localization of some SW I use DocFetcher to search the same strings in previously translated files. It is free and open-source, but needs to create index first. Just try it. :-)

share|improve this answer

Use "strings" provided by M$. They bought some very good utilities from Sysinternals a few years back. Doesn't require installation, just drop it on the box and run it for syntax. Easy to use and GREAT!

share|improve this answer

If you are happy on the command line/with Linux. Might I suggest looking at installing a version of grep for windows?

cygwin is a fairly handy way to got about that and will give you a full Linux environment, with bash shell and a rxvt terminal. Otherwise if you just want the tools there is gnuwin32 but then you will be stuck with the Windows cmd.exe prompt.

Microsoft actually have their own version of the Unix tools as a download, but they seemed fairly slow compared to the gnu ports when I tried them. They also going to scrap them with Windows 8.

share|improve this answer

Another grep implementation for Windows by the famous tortoise svn developers:

grepWin

share|improve this answer

This is how I search for text strings in the Windows Registry or files on my Windows XP machine. Let's assume I want to find the string "Enterprise" in a plain text file on the c: drive, then write the output to a file called search_result.txt in c:\windows\temp

Open a command prompt then type:

findstr "Enterprise" c:*.txt > c:\windows\temp\search_result.txt

The string you search for is case sensitive. "Enterprise" and "enterprise" will not find the same string.

share|improve this answer

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.