简体   繁体   English

如何使用PowerShell中的Get-Content和Select-String输出与'this_string'不匹配的行?

[英]How do I output lines that do not match 'this_string' using Get-Content and Select-String in PowerShell?

I found a post about users that wanted to use grep in PowerShell. 我发现了一篇关于想要在PowerShell中使用grep的用户的帖子。 For example, 例如,

PS> Get-Content file_to_grep | Select-String "the_thing_to_grep_for"

How do I output lines that are NOT this_string ? 如何输出非this_string

Select-String具有NotMatch参数。

get-content file_to_grep | select-string -notmatch "the_thing_to_grep_for"
get-content file_to_grep | select-string "^(?!the_thing_to_grep_for$)"

will return the lines that are different from the_thing_to_grep_for . 将返回与the_thing_to_grep_for不同的行。

get-content file_to_grep | select-string "^(?!.*the_thing_to_grep_for)"

will return the lines that don't contain the_thing_to_grep_for . 将返回不包含 the_thing_to_grep_for

gc  file_to_grep | ? {!$_.Contains("the_thing_to_grep_for")}

这是区分大小写的比较。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何显示使用get-content和select-string一个衬​​里找到匹配的文件 - How to display the file a match was found in using get-content and select-string one liner 是否可以使用Select-String cmdlet替换Get-Content,ForEach-Object字符串匹配? - Is it possible to replace Get-Content, ForEach-Object string -match with Select-String cmdlet? 如何使用Powershell select-string -Allmatch选择多个列并扩展属性? - How do I select multiple columns and expand properties using powershell select-string -Allmatch? 使用Powershell Get-Content时,如何使用反斜杠替换字符串 - When using Powershell Get-Content, how do you replace a string with a backslash Powershell Select-String:如何获取fullPath和上下文行 - Powershell Select-String : how to get fullPath and context lines 如何使用 PowerShell 中的选择字符串查找字符串不匹配的文件? - How to find a file with not match string using select-string in PowerShell? 如何在PowerShell中使用Select-String和regex匹配捕获值? - How do I capture a value using Select-String and regex matching in PowerShell? 如何从PowerShell中的选择字符串获取匹配值 - How to get value of a match from Select-String in PowerShell Powershell:如何使用“选择字符串”“grep”命令的输出? - Powershell: how to “grep” the output of a command by using “select-string”? 如何在 Powershell 中使用 select-string 进行多个管道 - How to do multiple piping with select-string in Powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM