Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell FINDSTR eqivalent?

What's the DOS FINDSTR equivalent for PowerShell? I need to search a bunch of log files for "ERROR".

like image 453
Monroecheeseman Avatar asked Aug 18 '08 14:08

Monroecheeseman


People also ask

Is there something like grep in PowerShell?

The Select-String cmdlet searches for text and text patterns in input strings and files. You can use it like Grep in UNIX and Findstr in Windows with Select-String in PowerShell. Select-String is based on lines of text.

What's grep in PowerShell?

Grep's core is simply the ability to search plain text for a RegEx pattern. Grep can search files in a given directory or streamed input to output matches. Did you know PowerShell has grep? Well.. almost.

How do I select multiple strings in PowerShell?

To search for multiple matches in each file, we can sequence several Select-String calls: Get-ChildItem C:\Logs | where { $_ | Select-String -Pattern 'VendorEnquiry' } | where { $_ | Select-String -Pattern 'Failed' } | ...

What is $_ in PowerShell?

The “$_” is said to be the pipeline variable in PowerShell. The “$_” variable is an alias to PowerShell's automatic variable named “$PSItem“. It has multiple use cases such as filtering an item or referring to any specific object.


1 Answers

Here's the quick answer

Get-ChildItem -Recurse -Include *.log | select-string ERROR  

I found it here which has a great indepth answer!

like image 139
Monroecheeseman Avatar answered Sep 24 '22 06:09

Monroecheeseman