Find files which does not contains selected string

前端 未结 3 1326
独厮守ぢ
独厮守ぢ 2021-02-04 05:25

I am trying to find all files, which does not contains a selected string. Find files which contains is easy:

gci | select-string \"something\"

相关标签:
3条回答
  • 2021-02-04 06:06

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

    Select-String has the NotMatch parameter.

    So you could use it:

    gci | Select-String -notmatch "something"
    
    0 讨论(0)
  • 2021-02-04 06:09

    I'm not sure if it can be done without the foreach-object but this works:

    gci |foreach-object{if (-not (select-string -inputobject $_ -Pattern "something")){$_}}
    
    0 讨论(0)
  • 2021-02-04 06:11

    You can use Where-Object;

    gci | Where-Object { !( $_ | Select-String "something" -quiet) }
    
    0 讨论(0)
提交回复
热议问题