Saturday, January 4, 2025
HomeTechPowerShell Equivalent to grep -f

PowerShell Equivalent to grep -f

In PowerShell, you can use Select-String to mimic grep -f, which matches patterns from a file. Here’s how:

powershell
Select-String -Path "file.txt" -Pattern (Get-Content "patterns.txt")
  • -Path: Specifies the file to search (file.txt).
  • Get-Content: Reads patterns from patterns.txt.
  • -Pattern: Matches lines based on patterns.
See also  How to Print in Java

This searches file.txt for lines matching patterns listed in patterns.txt.

RELATED ARTICLES

Leave a Reply

- Advertisment -

Most Popular

Recent Comments