PowerShell类grep

PowerShell类grep

 

方法一:

windows下没有grep不过有findstr, 功能差不多

 

方法二:

powershell自带的正择功能

xxx | where {$_ -match "alicloud_slb"}

不过一个常用功能这么长写起来太麻烦了, 顺手写个脚本:

 1 function Win-Grep
 2 {
 3     param(
 4         [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
 5         $pipelineInput,
 6         [Parameter(Mandatory=$true,ValueFromPipeline=$false)]
 7         $grep
 8     )
 9 
10     Process {
11         $out = @()
12         ForEach($input in $pipelineInput)
13         {
14             if($input -match $grep)
15             {
16                 $out = $out + $input
17             }
18         }
19         return $out
20     }
21 }

 

posted @ 2020-03-18 13:39  酱_油  阅读(1350)  评论(0编辑  收藏  举报