Windows命令相当于egrep

问题描述:

我可以在Windows命令提示符下运行此命令,就像我可以在UNIX中运行它一样吗?Windows命令相当于egrep

egrep -wi 'FRIENDS|FOES' *.sql 

该指令旨在扫描每个SQL文件为整个关键字“朋友”和“仇敌”,不区分大小写。

+3

你有没有看findstr命令? http://technet.microsoft.com/en-us/library/bb490907.aspx – selbie 2012-02-02 08:31:01

+2

这个问题为什么downvoted? Windows CLI缺少我们Linux避难所认为理所当然的一些功能。 – dotancohen 2012-03-01 10:12:01

我觉得findstr命令到位Linux的一个很公平的替代Windows命令。

取决于您的系统。你有没有安装一些版本的grep? Windows并没有开箱即用,但你可以安装Cygwin/GnuWin或unxutils.sourceforge.net

那么你可以在Windows cygwin,那么你有bashgrep

如果您只需要grep的,再有就是GnuWin32

如果你不想安装任何东西,并且在Win XP上,请尝试findstr,尽管它不能做“orring”。

如果你在Win-7上,那么有powershellselect-string

在Windows相当于将find命令:

 
C:\>find /? 
Searches for a text string in a file or files. 

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]] 

    /V   Displays all lines NOT containing the specified string. 
    /C   Displays only the count of lines containing the string. 
    /N   Displays line numbers with the displayed lines. 
    /I   Ignores the case of characters when searching for the string. 
    /OFF[LINE] Do not skip files with offline attribute set. 
    "string" Specifies the text string to find. 
    [drive:][path]filename 
      Specifies a file or files to search. 

If a path is not specified, FIND searches the text typed at the prompt 
or piped from another command. 

但你也可以从http://gnuwin32.sourceforge.net/下载大部分的UNIX实用程序(包括grep的。)(只是拖放到你的路径并使用它们)。

我不确定有关OR条件,但基本功能应该像

type *.sql | find /n "FRIENDS" 

这里是egrep命令一个相当于 “字符串1 |字符串2 | STRING3”:

PS:C:> FINDSTR/C:字符串1/C:字符串2/C:STRING3