关于Windows的grep工具有什么建议吗?理想情况下,可以利用64位操作系统。
当然,我知道Cygwin,也发现了PowerGREP,但我想知道是否有任何隐藏的宝石在那里?
关于Windows的grep工具有什么建议吗?理想情况下,可以利用64位操作系统。
当然,我知道Cygwin,也发现了PowerGREP,但我想知道是否有任何隐藏的宝石在那里?
当前回答
ack在Windows上工作得很好(如果您有Perl)。我发现它在很多方面比grep更好。
其他回答
多年来,我每天都在使用AJC Grep。我发现的唯一主要限制是文件路径被限制在255个字符,当遇到一个字符时它就会停止,而不仅仅是发出警告。这很烦人,但不经常发生。
我在64位的Windows 7 Ultimate上使用它,所以它的64位凭证没问题。
dnGREP是一个开源的Windows grep工具。它支持许多很酷的功能,包括:
撤销替换 能力搜索右键单击文件夹在资源管理器 高级搜索选项,如语音搜索和xpath 在PDF文件、档案和Word文档中搜索
恕我直言,它也有一个漂亮干净的界面:)
PowerShell的Select-String cmdlet在v1.0中很好,但在v2.0中明显更好。在最新版本的Windows中内置PowerShell意味着你在这里的技能总是有用的,而不需要先安装什么。
新的参数添加到Select-String: Select-String cmdlet现在支持新的参数,例如: 上下文:这个选项允许你查看匹配行之前和之后的行 -AllMatches:允许你看到一行中的所有匹配(以前,你只能看到一行中的第一个匹配) -NotMatch:等价于grep -v o -Encoding:指定字符编码
我发现为Get-ChildItem -Recurse .创建一个函数gcir比较方便,使用smarts来正确传递参数,并为Select-String创建一个别名ss。所以你可以这样写:
Gcir *.txt | ss foo
FINDSTR相当强大,支持正则表达式,并且具有在所有Windows机器上都可以运行的优点。
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
用法示例:findstr text_to_find *或递归搜索findstr /s text_to_find *
我推荐AstroGrep。
它是免费的,开源的,并且有一个简单的界面。我一直用它来搜索代码。