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 }