What is the equivalent of the grep command in Windows?

16

In Linux, when I want to filter by a term when a command will generate a giant list, I use the command grep .

For example:

 ls | grep "termo"

However, in Windows there is no command grep .

What would be the equivalent of grep in Windows for both Power Shell and CMD?

    
asked by anonymous 27.06.2017 / 15:07

2 answers

25

You can use two options in Windows:

Using Command Prompt: Findstr

Examples:

Search for files that contain the expression: log : dir /B | findstr /R /C:"[log]" :

where:

  • dir/B:Liststhefiles/directoriesfromthecurrentdirectory.
  • findstr/R/C:Acceptsregularexpressionsandsearchesforaliteralstring,respectively.


Searchthecontentofthefile(s)fortheexpression:log:findstrlog*:


UsingPowerShell: Select-String

Example:

Search for files that contain the expression: log : Get-ChildItem *log* :

Findthecontentofthefile(s):log:Get-ChildItem|Select-String-Pattern"log" :

    
27.06.2017 / 15:39
10

I think you're looking for findstr in cmd

Example:

  

C: > dir / B | findstr / R / C: "[mp]"

In PowerShell it's sls:

  

PS C: > New-Alias Select-String sls

    
27.06.2017 / 15:11