title: Stable Partition shell program output
body: <p>I have a big directory that I'm trying to navigate. I am looking for file names that match a certain pattern. For this, i use the find command.</p>
  
  <p>There is also a subset of the filenames that match my pattern that contain a substring that i am interested in. I would like for those files to be printed first, while also having all the output ordered alphabetically (as if the values were partitioned and then the two partitions sorted separately or as if the output was sorted, then stably partitioned).</p>
  
  <p>I am running Ubuntu 18.04.1 LTS.</p>
  
  <p>So far I have only tried sorting the output, and grepping through it to filter out the file names that contain the substring I'm searching for. Not having to do that would be better though (The directory is pretty large and searching twice is kinda slow).</p>
  
  <pre><code>find . &lt;...more stuff comes here...&gt; | sort | grep &lt;substring&gt;
  find . &lt;...more stuff comes here...&gt; | sort | grep -v &lt;substring&gt;
  </code></pre>
  
  <p>I have also though of doing the following:</p>
  
  <pre><code>find . &lt;...more stuff comes here...&gt; | sort &gt; tempfile
  tempfile &gt; grep &lt;substring&gt;
  tempfile &gt;  grep -v &lt;substring&gt;
  rm tempfile
  </code></pre>
  
  <p>This is faster, but this way I still have to grep through the list twice, and do extra file IO in between, which feels wasteful.</p>
  
  <p>(By the way, I am not allowed to show the pattern or the substring.)</p>
  
  <p>In short: I want to see partitioned results instead of having to filter twice.</p>
  
  <p>EDIT: an example would be:
  with this output of the <code>find | sort</code> commands:</p>
  
  <pre><code>./aaaaaafoo
  ./bbbbbbfoo
  ./ccccccbar
  ./ddddddbar
  ./eeeeeefoo
  ./ffffffbaz
  ./ggggggfoobar
  ./hhhhhhbar
  </code></pre>
  
  <p>With substring <code>'foo'</code>, i want the output to be:</p>
  
  <pre><code>./aaaaaafoo
  ./bbbbbbfoo
  ./eeeeeefoo
  ./ggggggfoobar
  ./ccccccbar
  ./ddddddbar
  ./ffffffbaz
  ./hhhhhhbar
  </code></pre>