PowerShell: how to grep command output?

前端 未结 7 1323
温柔的废话
温柔的废话 2021-01-30 08:27

In PowerShell I have tried:

alias | select-string Alias

This fails even though Alias is clearly in the output. I know this is beca

7条回答
  •  走了就别回头了
    2021-01-30 08:39

    There are two problems. As in the question, select-string needs to operate on the output string, which can be had from "out-string". Also, select-string doesn't operate linewise on strings that are piped to it. Here is a generic solution

    (alias|out-string) -split "`n" | select-string Write 
    

提交回复
热议问题