powershell - 如何使用PowerShell选择字符串在文件中查找多个模式?

标签 powershell

我想在目录中的文件中搜索多个字符串,但是使用“select-string -pattern”无济于事。谁能告诉我该怎么做?

示例:在C:\ Logs中搜索包含单词“VendorEnquiry”和“Failed”的所有文件,并且日志时间约为上午11:30。文件的结构可能有所不同(例如,不同的标签名称等):

... <methodException>VendorEnquiry</methodException> ...
... <logTime>13/10/2010T11:30:04 am</logTime> ...
... <status>Failed</status> ...

... <serviceMethodException>VendorEnquiry</serviceMethodException> ...
... <logTime>13/10/2010</logTime> ...
... <serviceStatus>Failed</serviceStatus> ...

谢谢。

最佳答案

如果要按两个顺序匹配两个单词,请使用:

gci C:\Logs| select-string -pattern '(VendorEnquiry.*Failed)|(Failed.*VendorEnquiry)'

如果失败总是发生在VendorEnquiry之后,请使用:
gci C:\Logs| select-string -pattern '(VendorEnquiry.*Failed)'

关于powershell - 如何使用PowerShell选择字符串在文件中查找多个模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3920383/

相关文章:

windows - Powershell - 具有多个函数和 ArgumentList 的调用命令

powershell - 从catch block 运行时,为什么Invoke-WebRequest不跟随重定向

powershell - 如何在 PowerShell 中创建 Outlook 约会/ session ?

.net - Powershell 卸载模块...完全

powershell - 使用 Powershell 将 Active Directory 组移动到另一个 OU

powershell - 使用DirectorySearcher的Powershell LDAP过滤器

Powershell - 等待输入 10 秒

powershell - 在 PowerShell 中创建批处理作业

powershell - 使用Powershell执行命令以输出窗口

windows - CMD/Powershell : Commands not working with cURL. Cygwin 工作