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 }