[英]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.