相当于 egrep 的 Windows 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9109078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:10:47  来源:igfitidea点击:

Windows command equivalent of egrep

windowscommand

提问by Oh Chin Boon

Can I run this in a Windows command prompt like I can run it in UNIX?

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

egrep -wi 'FRIENDS|FOES' *.sql

This command is intended to scan each SQL file for the whole keywords "Friends" and "Foes," ignoring case.

此命令旨在扫描每个 SQL 文件以查找整个关键字“Friends”和“Foes”,忽略大小写。

采纳答案by Oh Chin Boon

I think the findstrcommand is a fair enough substitute Windows command in place of Linux.

我认为该findstr命令是一个足够公平的替代 Windows 命令来代替 Linux。

回答by Zsolt Botykai

Well you can have cygwinon Windows so then you have bash, grep, etc.

那么你可以有Cygwin的Windows上,那么你有bashgrep等。

If you need only grep, then there is GnuWin32.

如果您只需要 grep,则有GnuWin32

If you don't want to install anything and is on Win XP, try findstr, although it can't do "orring".

如果您不想安装任何东西并且使用的是 Win XP,请尝试findstr,尽管它不能执行“orring”。

If you are on Win-7, then there is powershell, with select-string.

如果您使用的是 Win-7,则有powershell, 和select-string.

回答by a_horse_with_no_name

The Windows equivalent would be the FIND command:

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.

But you can also download most of the unix utilities (incl. grep) from http://gnuwin32.sourceforge.net/(just drop them into your PATH and use them).

但是您也可以从http://gnuwin32.sourceforge.net/下载大多数 unix 实用程序(包括 grep)(只需将它们放入您的 PATH 并使用它们)。

回答by Dominik

I′m not sure about the OR condition, but the basic feature should look like

我不确定 OR 条件,但基本特征应该是这样的

type *.sql | find /n "FRIENDS"

回答by Mithrandir

Depends on your system. Do you have some version of grep installed? Windows has no equvalent of grep out of the box, but you can install Cygwin / GnuWin or unxutils.sourceforge.net.

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

回答by Frank Kou

Here is a equivalent to egrep "string1|string2|string3":

这里相当于 egrep "string1|string2|string3":

PS: C:> findstr /C:string1 /C:string2 /C:string3

PS:C:> findstr /C:string1 /C:string2 /C:string3