PowerShell类grep

你离开我真会死。 提交于 2020-03-18 14:19:33

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 }

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!