title: Sort alphabetically lines between 2 patterns in Bash
body: <p>I'd like to alphabetically lines between 2 patterns in a Bash shell script.</p>
  
  <p>Given the following input file:</p>
  
  <pre class="lang-none prettyprint-override"><code>aaa
  bbb
  PATTERN1
  foo
  bar
  baz
  qux
  PATTERN2
  ccc
  ddd
  </code></pre>
  
  <p>I expect as output:</p>
  
  <pre class="lang-none prettyprint-override"><code>aaa
  bbb
  PATTERN1
  bar
  baz
  foo
  qux
  PATTERN2
  ccc
  ddd
  </code></pre>
  
  <p>Preferred tool is an AWK "one-liner". Sed and other solutions also accepted. It would be nice if an explanation is included. </p>