简体   繁体   中英

Windows command equivalent of egrep

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

egrep -wi 'FRIENDS|FOES' *.sql

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

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

If you need only grep, then there is GnuWin32 .

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

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

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

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 .

The Windows equivalent would be the FIND command:

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).

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

type *.sql | find /n "FRIENDS"

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM