9
3
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.
9
3
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.
11
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 :)
Yeah, I must admit, I've used Notepad++ for this before. – Jon Cage – 2012-06-13T13:43:30.570
1
@JonCage there's somebody in this thread http://www.sevenforums.com/software/231954-can-any-uninstaller-accurately-monitor-installation-2.html 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 – 2012-06-13T15:45:03.990Notepad++ is great. Other programmer's editors like SciTE have similar functionality as well. – TimothyAWiseman – 2012-06-18T20:55:15.140
5
Findstr
always works for me. It can use text * wildcards or regex for the search string. Findstr /?
for more
5
Agent Ransack works like a charm. Download it here.
Agent Ransack was the old name, now its called File Locator Lite – rubber boots – 2012-06-13T16:59:43.677
5
On Unix systems people would most likely use grep to do this, so why not use Windows Grep?
wingrep is discontinued, however grepwin is still available and works very well.
– techturtle – 2017-03-09T17:25:39.843Windows Grep can sometime become unstable, but it is the fastest searching program I have ever used. – yakatz – 2012-06-13T20:32:27.293
@yakatz Thanks for mentioning possible instability with Windows Grep, I will look for a different grep/replace tool! – pacoverflow – 2014-05-22T07:06:48.550
3
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
Are you sure -filter "*.cpp","*.h"
does accept multiple extensions? This should rather read -include ("*.cpp","*.hpp")
– mloskot – 2018-03-28T09:03:16.900
I was about to post the same thing :) – Caleb Jares – 2012-06-13T21:14:45.340
2
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. :-)
1
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!
1
Another grep
implementation for Windows by the famous tortoise svn developers:
0
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.
0
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.
4
possible duplicate of Best way to confidently search files and contents in Windows without using an indexing service?
– Der Hochstapler – 2012-06-13T14:00:53.153