PowerShell equivalent to grep -f

前端 未结 9 1675
情书的邮戳
情书的邮戳 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条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 16:26

    So I found a pretty good answer at this link: https://www.thomasmaurer.ch/2011/03/powershell-search-for-string-or-grep-for-powershell/

    But essentially it is:

    Select-String -Path "C:\file\Path\*.txt" -Pattern "^Enter REGEX Here$"
    

    This gives a directory file search (*or you can just specify a file) and a file-content search all in one line of PowerShell, very similar to grep. The output will be similar to:

    doc.txt:31: Enter REGEX Here
    HelloWorld.txt:13: Enter REGEX Here
    

提交回复
热议问题