Tools to search for strings inside files without i

2020-01-29 03:36发布

I have to change some connection strings in an incredibly old legacy application, and the programmers who made it thought it would be a great idea to plaster the entire app with connection strings all over the place.

Visual Studio's "current project" search is incredible slow, and I don't trust Windows Search.

So, what's the best free, non-indexed text search tool out there? All it should do is return a list with files that contain the wanted string inside a folder and its subfolders.

I'm running Windows 2003 Server.

17条回答
▲ chillily
2楼-- · 2020-01-29 03:39

Visual Studio's search in folders is by far the fastest I've found.

I believe it intelligently searches only text (non-binary) files, and subsequent searches in the same folder are extremely fast, unlike with the other tools (likely the text files fit in the windows disk cache).

VS2010 on a regular hard drive, no SSD, takes 1 minute to search a 20GB folder with 26k files, source code and binaries mixed up. 15k files are searched - the rest are likely skipped due to being binary files. Subsequent searches in the same folder are on the order of seconds (until stuff gets evicted form the cache).

The next closest I've found for the same folder was grepWin. Around 3 minutes. I excluded files larger than 2000KB (default). The "Include binary files" setting seems to do nothing in terms of speeding up the search, it looks like binary files are still touched (bug?), but they don't show up in the search results. Subsequent searches all take the same 3 minutes - can't take advantage of hard drive cache. If I restrict to files smaller than 200k, the initial search is 2.5min and subsequent searches are on the order of seconds, about as fast as VS - in the cache.

Agent Ransack and FileSeek are both very slow on that folder, around 20min, due to searching through everything, including giant multi-gigabyte binary files. They search at about 10-20MB per second according to Resource Monitor.

UPDATE: Agent Ransack can be set to search files of certain sizes, and using the <200KB cutoff it's 1:15min for a fresh search and 5s for subsequent searches. Faster than grepWin and as fast as VS overall. It's actually pretty nice if you want to keep several searches in tabs and you don't want to pollute the VS recently searched folders list, and you want to keep the ability to search binaries, which VS doesn't seem to wanna do. Agent Ransack also creates an explorer context menu entry, so it's easy to launch from a folder. Same as grepWin but nicer UI and faster.

My new search setup is Agent Ransack for contents and Everything for file names (awesome tool, instant results!).

查看更多
Luminary・发光体
3楼-- · 2020-01-29 03:39

TextPad is really good for this sort of thing. You can use it for free, but you get a warning message asking you to buy it. Other than that it is an excellent tool all round.

查看更多
你好瞎i
4楼-- · 2020-01-29 03:41

FileSearchy. It's quick and free. It does have indexing, but only for file names and not contents.

查看更多
Summer. ? 凉城
5楼-- · 2020-01-29 03:41

I can recommend ack - a command line program with linux roots, which fortunately works great also on Windows. It's faster than grep, it ignores git/subversion directories and binary files, and the output is more comprehensible. And typing ack is 25% faster than grep ;)

http://beyondgrep.com/

I tried it on babun (cygwin) and msys from git - works fabulously. It's written in perl so should work also in cmd.exe with perl installed somewhere on OS.

查看更多
趁早两清
6楼-- · 2020-01-29 03:42

There is also a Windows built-in program called findstr.exe with which you can search within files.

>findstr /s "provider=sqloledb" *.cs
查看更多
Fickle 薄情
7楼-- · 2020-01-29 03:42

If you don't want to install Non-Microsoft tools, please download STRINGS.EXE from Microsoft Sysinternals and make a procedure like this one:

@echo off
if '%1' == '' goto NOPARAM
if '%2' == '' goto NOPARAM
if not exist %1 goto NOFOLDER

echo ------------------------------------------
echo - %1 : folder
echo - %2 : string to be searched in the folder
echo - PLEASE WAIT FOR THE RESULTS ...
strings -s %1\* | findstr /i %2 > grep.txt
notepad.exe grep.txt

goto END

:NOPARAM rem - input command not correct
echo ====================================
echo Usage of GREP.CMD:
echo   Grep "SearchFolder" SearchString
echo Please specify all parameters
echo ====================================
goto END

:NOFOLDER
echo Folder %1 does not exist
goto END

:END rem - exit
查看更多
登录 后发表回答