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

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


当前回答

多年来,我每天都在使用AJC Grep。我发现的唯一主要限制是文件路径被限制在255个字符,当遇到一个字符时它就会停止,而不仅仅是发出警告。这很烦人,但不经常发生。

我在64位的Windows 7 Ultimate上使用它,所以它的64位凭证没问题。

其他回答

我在我的机器上安装了Cygwin,并将Cygwin bin目录放在我的环境路径中,因此Cygwin grep在命令行中正常工作,这解决了目前我对grep的所有脚本编写需求。

GREP for Windows

我一直在用它,幸运的是它仍然可用。它非常快,非常小。

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 *

PowerShell已经被提到过几次了。下面是你如何以一种令人作呕的方式使用它:

Get-ChildItem -recurse -include *.txt | Select-String -CaseSensitive "SomeString"

它递归地搜索当前目录树中的所有文本文件,查找区分大小写的SomeString。

更好的是,运行这个:

function pgrep { param([string]$search, [string]$inc) Get-ChildItem -recurse -include $inc | Select-String -CaseSensitive $search }

然后做:

pgrep SomeStringToSearch *.txt

然后,为了让它变得神奇,将函数别名添加到PowerShell配置文件中,您几乎可以减轻没有合适的命令行工具的痛苦。

如果没有一个解决方案是您正在寻找的,也许您可以为FindStr编写一个包装器,以完成您所需要的工作。

FindStr是非常好的,所以它应该只是敲了一个GUI(如果你想要它),并提供了一些额外的功能(如将它与Find结合,以查找包含指定字符串的文件的计数[如上所述])。

当然,前提是你有需求、时间和意愿去做这件事!