首页 > 系统相关 >PowerShell Select-String:在字符串和文件中查找文本

PowerShell Select-String:在字符串和文件中查找文本

时间:2024-08-30 14:29:31浏览次数:4  
标签:String Pattern 查找 Path txt PowerShell Select

语法

Select-String
      [-Culture <String>]
      [-Pattern] <String[]>
      [-Path] <String[]>
      [-SimpleMatch]
      [-CaseSensitive]
      [-Quiet]
      [-List]
      [-NoEmphasis]
      [-Include <String[]>]
      [-Exclude <String[]>]
      [-NotMatch]
      [-AllMatches]
      [-Encoding <Encoding>]
      [-Context <Int32[]>]
      [<CommonParameters>]

Demo1::查找区分大小写的匹配项

'Hello', 'HELLO' | Select-String -Pattern 'HELLO' -CaseSensitive -SimpleMatch

Demo2:查找文本文件中的匹配项

Select-String -Path .\*.txt -Pattern 'Get-'

Demo3:查找与模式不匹配的字符串

Select-String -Path .\Command.txt -Pattern 'Get', 'Set'  -NotMatch

Demo4:把匹配结果输出为文件

Select-String -Path .\Command.txt -Pattern 'Get', 'Set'   | Out-File 'C:\match.txt'

Demo5:匹配多个关键字

'a','afsss','dd','fff','ggg' | Select-String -Pattern '[a-zA-Z]+(sss|ggg)'

 

 

References:

Select-String

 

标签:String,Pattern,查找,Path,txt,PowerShell,Select
From: https://www.cnblogs.com/CRobot/p/18388691

相关文章

  • [WPF]数据绑定时为何会出现StringFormat失效
    在数据绑定过程中,我们经常会使用StringFormat对要显示的数据进行格式化,以便获得更为直观的展示效果,但在某些情况下格式化操作并未生效,例如Button的Content属性以及ToolTip属性绑定数据进行StringFormat时是无效的。首先回顾一下StringFormat的基本用法。StringFormat的用法Str......
  • [WPF]数据绑定时为何会出现StringFormat失效
    在数据绑定过程中,我们经常会使用StringFormat对要显示的数据进行格式化,以便获得更为直观的展示效果,但在某些情况下格式化操作并未生效,例如Button的Content属性以及ToolTip属性绑定数据进行StringFormat时是无效的。首先回顾一下StringFormat的基本用法。StringFormat的用法Str......
  • 数据库学习(一)——select语句
    一.检索数据1.SELECTprod_nameFROMproducts;--//从表products中检索一个名为prod_name的列。2.SELECTprod_id,prod_name,prod_priceFROMproducts;--//从表products中检索名为prod_id,prod_name,prode_price的列。3.SELECT*FROMprdoucts;--//检索表products中的所有的......
  • Java中的String、StringBuilder、StringBuffer
            在Java中,String、StringBuilder 和 StringBuffer 是处理字符串的三个常用类,它们各有特点和适用场景。以下是对这三个类的详细解释、常用方法的代码示例以及它们之间的区别和适用场景。StringString 类表示不可变的字符序列。一旦创建,String 对象的内容......
  • html之select标签
    1.select标签用于做下拉选择框2.select元素中的option标签定义了列表中的可用选项3.selected表示默认,一般用在option标签里Select对象属性属性描述W3Cdisabled设置或返回是否应禁用下拉列表Yesform返回对包含下拉列表的表单的引用Yeslength返回下拉......
  • Mybatis-puls中select查询方法报错Can not find table primary key in Class
    1、项目参数springboot2.6.13jdk8Mybatis-Plus3.5.42、问题描述Mybatis-puls中select查询方法报错CannotfindtableprimarykeyinClass,org.apache.ibatis.binding.BindingException:Invalidboundstatement(notfound):com.example.dao.FLowerDao.selectById3、......
  • 【mysql】SUBSTRING_INDEX 用法举例
    查询语句如下:SELECT 高工, SUBSTRING_INDEX(高工,'、',-1), --取右边第一个 SUBSTRING_INDEX(高工,'、',0), SUBSTRING_INDEX(高工,'、',1), --取左边一个(从左往右) SUBSTRING_INDEX(高工,'、',2), --取左边二个(从左往右) SUBSTRING_INDEX(高工,'、&......
  • Mybatis-puls中select查询方法返回为空null
    1、项目参数springboot2.6.13jdk8Mybatis-Plus3.5.42、问题描述在3.5.4版本的MP中使用select方法查询到数据,却返回为空实体类publicclassFlower{@TableId(value="flower_id",type=IdType.INPUT)privateintflower_id;privateStringflower_name;......
  • powershell 创建winform窗体 T2 : 自动配置相机网卡参数
    <#脚本功能说明:选择要配置的相机网卡,点击配置按键,自动配置参数#2024.08.29#>#获取管理员权限if(-NOT([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator......
  • string
    stringstring作为类出现,其集成的操作函数足以完成多数情况下的需要。可以使用"="进行赋值,使用"=="进行等值比较,使用"+"做串联。要使用string类,必须包含头文件<string>。在STL库中,basic_string有两个预定义类型:包含char的string类型和包含wchar的wstring类......