PowerShell equivalent to grep -f

前端 未结 9 1659
情书的邮戳
情书的邮戳 2020-12-22 16:09

I\'m looking for the PowerShell equivalent to grep --file=filename. If you don\'t know grep, filename is a text file where each line has a regular

9条回答
  •  猫巷女王i
    2020-12-22 16:30

    The -Pattern parameter in Select-String supports an array of patterns. So the one you're looking for is:

    Get-Content .\doc.txt | Select-String -Pattern (Get-Content .\regex.txt)
    

    This searches through the textfile doc.txt by using every regex(one per line) in regex.txt

提交回复
热议问题