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