曾经不得不在一堆不同的文本文件中找到一些文本吗?如果您从事 IT 行业,这个问题可能会经常出现。也许您正在日志文件中寻找特定的短语,或者您是一名程序员并且需要在许多不同的代码文件中查找一些代码。
不幸的是,在Windows(Windows)中没有任何简单的方法可以做到这一点。默认的Windows搜索对于此类任务来说很糟糕,因为它非常慢并且不允许进行高级搜索。幸运的是,还有其他几种方式远优于Windows搜索,我将在这篇文章中提到。我不会详细介绍每种解决方案,但您可以使用Google了解更多信息。
如果您不想安装任何第三方软件并且您对命令行感到满意,那么您应该查看下面的内置搜索命令部分。我假设大多数人更喜欢GUI界面,所以这就是我首先提到这些程序的原因。
第三方搜索程序
在搜索多个文本文件时,所有搜索命令之王是 grep。grep 是UNIX/Linux中的命令行实用程序,允许您使用正则表达式执行高级搜索。它非常流行,并在每个Linux发行版中使用。
所以当有人写一个在Windows(Windows)上搜索的程序时,难免会有 grep 这个词。下面列出的所有程序几乎都是这种情况。
grepWin
grepWin可能是这里提到的工具中最受欢迎的。它支持正则表达式,还允许您查找和替换文本。他们在他们的网站上也有一个教程来帮助使用正则表达式,尽管你可以谷歌搜索更多。
您可以按文件大小、文件类型和其他条件限制搜索。它还在资源管理器(Explorer)中的右键单击上下文菜单中添加了一个选项,以快速搜索文件夹。结果列在底部窗口中,您只需双击它们即可打开文件。
AstroGrep
AstroGrep也是另一个非常好的搜索程序。它不仅会经常更新,还会向您显示在文件中找到文本的位置。如果您选择Content单选按钮,grepWin 也有该选项,但我认为它在AstroGrep中实现得更好。
AstroGrep还可以搜索Word文件,这是一个方便的功能。您还可以保存或打印所有结果以供将来参考。我还发现他们的界面更现代,更赏心悦目。
BareGrep
BareGrep是一个相当简单的搜索程序,它支持正则表达式和所有基本的搜索功能。它总体上非常快,并以表格格式显示您的匹配项。免费版有一个您无法禁用的启动画面。专业版售价 25 美元,似乎只是禁用了启动画面,否则功能是相同的。
PowerGREP
如果您正在寻找终极搜索程序,那么请寻找比PowerGREP更远的地方。这个程序有一些重要的功能和一个严肃的价格标签。这是一个惊人的159美元!它几乎包含了上面提到的所有功能,以及更多功能,并且都很好地打包到一个漂亮的小界面中。
如果你有一些严肃的搜索需求,包括在Word文件、PDF文档、Excel电子表格等中查找文本,我只推荐这个程序。它甚至可以从你的日志文件中提取统计数据并将这些信息提供给你。这是一个相当强大的工具。
内置 Windows 命令
如果您只需要执行快速搜索并且不想安装成熟的程序,则可以使用Windows中的内置命令行工具。一个在普通命令提示符下运行,另一个使用PowerShell。两者都非常强大,几乎可以找到您正在寻找的任何东西。
第一个命令是findstr。您可以在此处阅读参考文档(reference document)以了解如何使用 findstr。你也可以输入findstr /?在命令提示符下,它会向您显示用法。如您所见,有很多选择。显然,这比使用上述程序之一复杂得多。
第二个选项是Windows PowerShell中的 Select-String 命令。同样(Again),如果您还没有使用过这些命令,那么这些命令的学习曲线会相当长。Microsoft有一个关于如何使用 Select-String(how to use Select-String)的很好的教程,所以一定要阅读它。
因此,这些基本上是在大量文件中搜索文本的最佳方法。我建议您尝试不同的选项,看看哪一个最适合您。享受!
Search Inside Multiple Text Files at Once
Ever had to find somе text inside a bunch of dіfferent text files? If you’re in IT, this issue can come up quite often. Maybе yоu are looking for а particular phrase in log files or maybe you are a programmer and need to find ѕome code that is inside many different code files.
Unfortunately, there isn’t any easy way to do this in Windows. The default Windows search is terrible for this kind of task because it’s super slow and doesn’t allow for advanced searches. Luckily, there are several other ways that are far superior to Windows search, which I will mention in this post. I won’t go into great detail about each solution, but you can use Google to learn more.
If you don’t want to install any third-party software and you are comfortable with the command line, then you should check out the built-in search commands section below. I’m assuming most people are more comfortable with GUI interfaces, so that’s why I mention the programs first.
Third-Party Search Programs
When it comes to searching multiple text files, the king of all search commands is grep. grep is a command line utility in UNIX/Linux that allows you to perform advanced searches using regular expressions. It’s super popular and used in every distribution of Linux.
So when someone writes a program for searching on Windows, inevitably, it has the word grep in it. That’s pretty much the case with all the programs listed below.
grepWin
grepWin is probably the most popular out of the tools mentioned here. It supports regular expressions and allows you to find and replace text also. They also have a tutorial on their website to help with regular expressions, though you can Google for many more.
You can limit the search by file size, file type and other criteria. It also adds an option to the right-click context menu in Explorer to quickly search a folder. The results are listed in the bottom window and you can just double-click on them to open the files.
AstroGrep
AstroGrep is also another really good search program. Not only does it get updated quite often, it also shows you where in the file the text was found. grepWin also has that option if you choose the Content radio button, but I think it’s implemented better in AstroGrep.
AstroGrep can also search Word files, which is a handy feature. You can also save or print out all of the results for future reference. I also find their interface to be more modern and pleasing to the eye.
BareGrep
BareGrep is a fairly simple search program that supports regular expressions and all the basic search functions. It’s pretty fast overall and shows you matches in a tabular format. The free version has a splash screen that you can’t disable. The pro version costs $25 and seems to just disable the splash screen, otherwise the features are the same.
PowerGREP
If you are looking for the ultimate search program, then look for further than PowerGREP. This program has some serious features and a serious price tag to go along with it. It’s a whopping $159! It’s pretty much got all the features mentioned above, plus some more, and all packaged nicely into a pretty little interface.
I only recommend this program if you have some serious search needs that include finding text in Word files, PDF documents, Excel spreadsheets, etc. It can even extract statistics from your log files and give that information to you. It’s quite a powerful tool.
Built-in Windows Commands
If you only need to perform a quick search and don’t want to install a full-fledged program, you can use the built-in command line tools in Windows. One runs in the normal command prompt and the other uses PowerShell. Both are quite powerful and can find pretty much anything you are looking for.
The first command is findstr. You can read the reference document here to learn how to use findstr. You can also type findstr /? at the command prompt and it’ll show you the usage. As you can see, there are quite a few options. Obviously, this is a lot more complicated than using one of the programs above.
The second option is the Select-String command in Windows PowerShell. Again, there is a pretty big learning curve with these commands if you haven’t already used them. Microsoft has a good tutorial on how to use Select-String, so make sure to read that.
So, those are basically the best ways to go about searching for text in a large number of files. I suggest you try out the different options and see which one works best for you. Enjoy!