特定の文字列を含まない特定のファイルのサブディレクトリの識別

特定の文字列を含まない特定のファイルのサブディレクトリの識別

dir1私はという名前の約800のサブディレクトリを含むというディレクトリを持っていますdisp-001, disp-002, ... disp-800。サブディレクトリを探す必要があります。

  • ファイルが含まれていstdoutない
  • ファイルがある場合、そのファイルには特定の文字列は含まれませんstr1

ファイルが含まれていないサブディレクトリを識別する答えは次のとおりです。別の問題

$ find . -type d \! -exec test -e '{}/stdout' \; -print

しかし、上記のコマンドにgrepを含めようとすると機能しません。

 $ find . -type d \! -exec test -e 'grep str1 {}/stdout' \; -print

興味のあるディレクトリを返すために文字列検索を含めるにはどうすればよいですか?

ベストアンサー1

そこにどんなソリューションでも適用できます。

  • 使用( -exec または -exec )そして持続可能な開発管理またはパトリック解決策(exec最初が返された場合にのみ2番目を実行しfalse-printどちらかが返された場合にのみ実行true):

    find . -type d \( ! -exec test -f '{}/stdout' \; -o ! -exec grep -q str1 '{}/stdout' \; \) -print
    

    または提案されているように短くコスタス:

    find . -type d \! -exec grep -q 'str1' {}/stdout 2>/dev/null \; -print
    
  • 利用規約テデン解決策:

    for d in **/
    do
      if [[ ! -f "$d"stdout ]] then
        printf '%s\n' "$d"
      else
        grep -q str1 "$d"stdout || printf '%s\n' "$d"
      fi
    done
    
  • または以下を使用してzsh

    print -rl **/*(/e_'[[ ! -f $REPLY/stdout ]] || ! grep -q str1 $REPLY/stdout'_)
    

おすすめ記事