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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM