title: Find all directories containing a file that contains a keyword in linux
body: <p>In my hierarchy of directories I have many text files called STATUS.txt.  These text files each contain one keyword such as COMPLETE, WAITING, FUTURE or OPEN.  I wish to execute a shell command of the following form:</p>
  
  <p><code>./mycommand OPEN</code></p>
  
  <p>which will list all the directories that contain a file called STATUS.txt, where this file contains the text "OPEN"</p>
  
  <p>In future I will want to extend this script so that the directories returned are sorted. Sorting will determined by a numeric value stored the file PRIORITY.txt, which lives in the same directories as STATUS.txt. However, this can wait until my competence level improves.  For the time being I am happy to list the directories in any order.</p>
  
  <hr>
  
  <p>I have searched Stack Overflow for the following, but to no avail:</p>
  
  <ul>
  <li>unix filter by file contents</li>
  <li>linux filter by file contents</li>
  <li>shell traverse directory file contents</li>
  <li>bash traverse directory file contents</li>
  <li>shell traverse directory find</li>
  <li>bash traverse directory find</li>
  <li>linux file contents directory</li>
  <li>unix file contents directory</li>
  <li>linux find name contents</li>
  <li>unix find name contents</li>
  <li>shell read file show directory</li>
  <li>bash read file show directory</li>
  <li>bash directory search</li>
  <li>shell directory search</li>
  </ul>
  
  <p>I have tried the following shell commands:</p>
  
  <p><em>This helps me identify all the directories that contain STATUS.txt</em></p>
  
  <pre><code>$ find ./ -name STATUS.txt
  </code></pre>
  
  <p><em>This reads STATUS.txt for every directory that contains it</em></p>
  
  <pre><code>$ find ./ -name STATUS.txt | xargs -I{} cat {}
  </code></pre>
  
  <p><em>This doesn't return any text, I was hoping it would return the name of each directory</em></p>
  
  <pre><code>$ find . -type d | while read d; do if [ -f STATUS.txt ]; then echo "${d}"; fi; done
  </code></pre>