关于Windows的grep工具有什么建议吗?理想情况下,可以利用64位操作系统。

当然,我知道Cygwin,也发现了PowerGREP,但我想知道是否有任何隐藏的宝石在那里?


当前回答

2013年7月更新:

我现在一直在Windows上使用的另一个grep工具是AstroGrep:

它的能力显示我不仅仅是行搜索(即命令行grep的——context=NUM)是无价的。 而且速度很快。非常快,即使是在非ssd驱动器的旧计算机上(我知道,他们过去用旋转磁盘来做这个硬盘驱动器,称为盘片,疯狂吧?)

它是免费的。 它是可移植的(简单的zip压缩文件解压缩)。


原答案2008年10月

Gnu Grep是好的

你可以下载,例如这里:(站点ftp)

所有常见的选项都在这里。

结合gawk和xargs(包括来自GnuWin32的'find'),你真的可以像在Unix上一样编写脚本!

也可以看到我使用grep递归的选项:

grep --include "*.xxx" -nRHI "my Text to grep" *

其他回答

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 *

GrepWin是免费的开源(GPL)

我一直在使用由一个TortoiseSVN人编写的grepWin。它在Windows上工作…

我用了Borland的grep很多年了,但我发现了一个不匹配的模式。嘿。这些年来,它还没有发现什么?我写了一个简单的文本搜索替换,像grep一样做递归-它是SourceForge上的FS.EXE。

grep失败...

C:\DEV> GREP GAAPRNTR \SOURCE\TPALIB\*.PRG
<no results>

Windows的findstr工作…

C:\DEV> FINDSTR GAAPRNTR \SOURCE\TPALIB\*.PRG
\SOURCE\TPALIB\TPGAAUPD.PRG:ffSPOOL(cRPTFILE, MEM->GAAPRNTR, MEM->NETTYPE)
\SOURCE\TPALIB\TPPRINTR.PRG:    AADD(mPRINTER,   TPACONFG->GAAPRNTR)
\SOURCE\TPALIB\TPPRINTR.PRG:               IF TRIM(TPACONFG->GAAPRNTR) <> TRIM(mPRINTER[2])
\SOURCE\TPALIB\TPPRINTR.PRG:                   REPLACE TPACONFG->GAAPRNTR WITH mPRINTER[2]

我用的是UnxUtils,它非常适合我……

ack在Windows上工作得很好(如果您有Perl)。我发现它在很多方面比grep更好。