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 }
复制代码

 

posted @   酱_油  阅读(1394)  评论(0编辑  收藏  举报
编辑推荐:
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
点击右上角即可分享
微信分享提示