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

chr*_*ips 18 powershell grep

我发现了一篇关于想要在PowerShell中使用grep的用户的帖子.例如,

PS> Get-Content file_to_grep | Select-String "the_thing_to_grep_for"
Run Code Online (Sandbox Code Playgroud)

如何输出不是的行this_string

man*_*lds 52

Select-String有NotMatch参数.

get-content file_to_grep | select-string -notmatch "the_thing_to_grep_for"
Run Code Online (Sandbox Code Playgroud)


Tim*_*ker 14

get-content file_to_grep | select-string "^(?!the_thing_to_grep_for$)"
Run Code Online (Sandbox Code Playgroud)

将返回不同的行the_thing_to_grep_for.

get-content file_to_grep | select-string "^(?!.*the_thing_to_grep_for)"
Run Code Online (Sandbox Code Playgroud)

将返回不包含 的行the_thing_to_grep_for.


vik*_*368 5

gc  file_to_grep | ? {!$_.Contains("the_thing_to_grep_for")}
Run Code Online (Sandbox Code Playgroud)

顺便说一下,这是区分大小写的比较。