The grep command is the most powerful UNIX utility for searching any given input files and matching using regular expressions and patterns. If you are looking for a command that works like the grep, you can make use of the Select-String cmdlet.
The Select-String cmdlet can be found in the Microsoft.PowerShell.Utility module of PowerShell. It can be used to find text in strings and files.
Syntax:
Select-String
[-Culture <String>]
[-Pattern] <String[]>
[-Path] <String[]>
[-SimpleMatch]
[-CaseSensitive]
[-Quiet]
[-List]
[-NoEmphasis]
[-Include <String[]>]
[-Exclude <String[]>]
[-NotMatch]
[-AllMatches]
[-Encoding <Encoding>]
[-Context <Int32[]>]
[<CommonParameters>]
Let's take a look at a few examples.
Example 1: Simple Text Matching
PS> 'Welcome to Code2care' | Select-String -Pattern 'Code2care' -SimpleMatch
Welcome to Code2care
Example 2: Simple Text Case Sensitive Matching
PS> 'Welcome to Code2care' | Select-String -Pattern 'Code2care' -SimpleMatch -CaseSensitive
Welcome to Code2care
Example 3: Find Matching Text Within a file
PS> Select-String ./file1.txt -Pattern "PowerShell"
file1.txt:2:PowerShell is fun!

Above examples are based on PowerShell Core version 7.3 on macOS.
Documentation:
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!