From the same wonderful folks who brought you RegexBuddy and who I have no affiliation with beyond loving their stuff. (应该注意的是RegexBuddy包含grep的基本版本(适用于Windows)本身,它的成本远低于PowerGREP . )
c:\> FindStr /?
Searches for strings in files.
FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
[/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
strings [[drive:][path]filename[ ...]]
/B Matches pattern if at the beginning of a line.
/E Matches pattern if at the end of a line.
/L Uses search strings literally.
/R Uses search strings as regular expressions.
/S Searches for matching files in the current directory and all
subdirectories.
/I Specifies that the search is not to be case-sensitive.
/X Prints lines that match exactly.
/V Prints only lines that do not contain a match.
/N Prints the line number before each line that matches.
/M Prints only the filename if a file contains a match.
/O Prints character offset before each matching line.
/P Skip files with non-printable characters.
/OFF[LINE] Do not skip files with offline attribute set.
/A:attr Specifies color attribute with two hex digits. See "color /?"
/F:file Reads file list from the specified file(/ stands for console).
/C:string Uses specified string as a literal search string.
/G:file Gets search strings from the specified file(/ stands for console).
/D:dir Search a semicolon delimited list of directories
strings Text to be searched for.
[drive:][path]filename
Specifies a file or files to search.
Use spaces to separate multiple search strings unless the argument is prefixed
with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or
"there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for
"hello there" in file x.y.
Regular expression quick reference:
. Wildcard: any character
* Repeat: zero or more occurances of previous character or class
^ Line position: beginning of line
$ Line position: end of line
[class] Character class: any one character in set
[^class] Inverse class: any one character not in set
[x-y] Range: any characters within the specified range
\x Escape: literal use of metacharacter x
\<xyz Word position: beginning of word
xyz\> Word position: end of word
28 回答
根据评论中的建议,我已经开始使用grepWin,它非常棒且免费 .
(我仍然是PowerGREP的粉丝,但我不再使用它了 . )
我知道你已经提到过,但PowerGREP是 awesome .
我最喜欢的一些功能是:
右键单击文件夹以在其上运行PowerGREP
使用正则表达式或文字文本
为要包含和排除的文件指定通配符
搜索和替换
预览模式很不错,因为你可以确保你正在替换你想要的东西 .
现在我意识到其他grep工具可以完成上述所有工作 . 只是PowerGREP将所有功能打包成一个非常易于使用的GUI .
From the same wonderful folks who brought you RegexBuddy and who I have no affiliation with beyond loving their stuff. (应该注意的是RegexBuddy包含grep的基本版本(适用于Windows)本身,它的成本远低于PowerGREP . )
其他解决方案
现有Windows命令
PowerShell中的
Windows上的Linux命令实现
Cygwin
Cash
Grep工具带有图形界面
AstroGrep
BareGrep
GrepWin
其他Grep工具
FINDSTR相当强大,支持regular expressions,并且具有已经在所有Windows机器上的优势 .
用法示例:
findstr text_to_find *
或递归搜索findstr /s text_to_find *
GrepWin 免费开源(GPL)
我一直在使用由一个tortoisesvn家伙写的grepWin . Windows上的工作是......
http://stefanstools.sourceforge.net/grepWin.html
2013年7月更新:
我现在在Windows上一直使用的另一个grep工具是AstroGrep:
它能够向我展示的不仅仅是行搜索(即--context =命令行grep的NUM)是非常宝贵的 .
它很快 . 非常快,即使在非驱动器的旧计算机上(我知道,他们曾经用旋转磁盘做这个硬盘,叫做platters,疯了吗?)
这是免费的 .
它是便携式的(解压缩的简单zip存档) .
原始答案2008年10月
Gnu Grep没事
你可以在这里下载它:(site ftp)
所有的_2906484都在这里 .
那,结合gawk和xargs(包括'find',来自GnuWin32),你可以像在Unix上一样编写脚本!
另见options I am using to grep recursively:
PowerShell的Select-String cmdlet在v1.0中运行良好,但是significantly better for v2.0 . 将PowerShell内置到最新版本的Windows中意味着您的技能始终有用,无需先安装 .
我发现为
Get-ChildItem -Recurse .
创建一个函数gcir
,智能正确传递参数,以及Select-String
的别名ss
. 所以你写一下:它可能不完全属于'grep'类别,但如果没有名为AgentRansack的实用程序,我无法在Windows上使用它 . 它很简单,右键单击一个文件夹,点击"ransack.."并找到包含你要查找的内容的文件 . 非常快 .
Baregrep(Baretail也很好)
它's been a couple of years since you asked the question, but I'推荐AstroGrep(http://astrogrep.sourceforge.net) .
它是免费的,开源的,并且具有简单的界面 . 我一直用它来搜索代码 .
PowerShell已被提及几次 . 以下是如何以实际的方式使用它:
它以区分大小写的形式递归搜索当前目录树中的所有文本文件
SomeString
.Even better, run this:
然后做:
然后真正让它变得神奇,将函数别名添加到PowerShell Profile中,你几乎可以消除没有正确命令行工具的痛苦 .
Cygwin包括grep . 如果安装Cygwin,所有GNU工具和Unix的东西在Windows上运行良好 .
http://www.cygwin.com/
ack在Windows上运行良好(如果你有Perl) . 对于许多用途我发现它比grep更好 .
Git on Windows = grep in cmd.exe
我刚刚发现安装Git会给你一些基本的Linux命令:cat,grep,scp和所有其他好的命令 .
安装然后将Git bin文件夹添加到PATH,然后您的cmd.exe具有基本的Linux功能!
http://code.google.com/p/msysgit/downloads/list?can=3
dnGREP是一个用于Windows的开源grep工具 . 它支持许多很酷的功能,包括:
撤消替换
能够通过右键单击资源管理器中的文件夹进行搜索
高级搜索选项,如拼音搜索和xpath
在PDF文件,档案和Word文档中搜索
恕我直言,它有一个漂亮和干净的界面:)
我总是使用WinGREP,但我遇到了问题,不放弃文件 .
那么,在GNU grep的Windows端口旁边:
http://gnuwin32.sourceforge.net/
还有免费软件Borland的免费C编译器中提供的Borland的grep(非常类似于GNU)(它是一个带命令行工具的免费软件) .
我已经成功使用GNU utilities for Win32已经有一段时间了,它有一个很好的grep以及tail和win32的其他方便的gnu工具 . 我避免使用打包的shell,只需在win32命令提示符下使用可执行文件即可 .
打包的Tail也是一个非常好的小应用程序 .
我是_2906521的作者_就像PowerGREP一样,它支持正则表达式,保存模式以供进一步使用,撤消替换,使用HTML / CSS / JS / PHP语法高亮预览,不同的编码,包括UTF-8和UTF-16 .
与PowerGREP相比,当您输入模式 (incremental search), 时,GUI立即开始搜索,因此您可以尝试使用正则表达式并立即查看结果 .
欢迎您试用我的工具;我很乐意回答任何问题 .
我想要一个适用于Windows的免费grep工具,它允许您右键单击文件夹并对每个文件进行正则表达式搜索 - 没有任何唠叨屏幕 .
以下是基于前一篇文章中提到的
findstr
的快速解决方案 .在硬盘驱动器的某个位置创建一个文本文件,您可以在其中保存长寿命工具 . 重命名为.bat或.cmd并将以下内容粘贴到其中:
然后浏览到SendTo文件夹 . 在Windows 7上,浏览到
%APPDATA%\Microsoft\Windows\SendTo
并将批处理文件的快捷方式拖到该SendTo文件夹中 .我将快捷方式重命名为
1 GREP
,使其保持在SendTo列表的顶部 .我想在下一步做的事情就是通过生成html文件的内容输出
findstr
的输出,以便您可以单击每个输出行来打开该文件 . 另外,我不必检查参数并查看它是否包含".lnk" .UnxUtils是我使用的,对我来说很完美......
我使用Borland的grep多年,但只是发现了一个不匹配的模式 . Eeeks . 多年来还发现了什么呢?我写了一个简单的文本搜索替换,它像grep一样进行递归 - 它是source forge上的FS.EXE .
grep失败了......
windows findstr的作品......
我选择的工具是适当命名的Windows Grep:
很好的简单GUI
支持搜索和替换
可以显示找到的线条周围的线条
可以在CSV和固定宽度文件中的列内搜索
如果你想要一个简单易用的Windows Grep工具,我创建了一个名为P-Grep的文件,我可以从我的网站免费下载:www.adjutantit.com - 主菜单,下载 .
Windows Grep似乎有大量文件的问题,所以我写了自己的 - 这似乎更可靠 . 您可以选择一个文件夹,右键单击并将其发送给P-Grep . sendto文件夹在安装期间未经过更新 .
另一个不错的选择是MSYS . 它为您提供了许多其他GNU实用程序,使您可以提高工作效率 .
PowerShell的select-string类似,它的选项和语义不同,但它仍然很强大 .
我多年来一直在使用AJC Grep . 我唯一的主要限制是令人烦恼,但并不经常发生 .
我在64位Windows 7旗舰版上使用它,所以它的64位凭证很好 .
GREP for Windows
我一直在使用它,幸运的是它仍然可用 . 它超级快,非常小 .
如果没有一个解决方案是你正在寻找的,也许你可以给FindStr写一个包装器,它完全符合你的要求吗?
无论如何,FindStr非常好,所以它应该只是敲击一个GUI(如果你想要的话)并提供一些额外的功能(比如将它与Find组合以查找包含指定字符串的文件的数量[如上所述]) .
当然,这假设您有这样的要求,时间和倾向!
我在我的机器上安装了Cygwin并将Cygwin bin目录放在我的环境路径中,因此Cygwin grep在命令行中正常工作,这解决了我目前对grep的所有脚本需求 .