Sort paragraphs in text file from bash
<p>The <code>sort</code> utility let's you conveniently sort lines in a file. However, is there an elegant way to sort blank-line separated paragraphs in bash?</p>

<p>For example</p>

<pre><code>ccc
aa

aba
bbb

aba
ccc

aaa
</code></pre>

<p>would have to become</p>

<pre><code>aaa

aba
bbb

aba
ccc

ccc
aa
</code></pre>

<p>One solution seems to be to replace new line symbol on all non-blank lines: </p>

<pre><code>ccc\naa    
aba\nbbb
aba\nccc
aaa
</code></pre>

<p>then call run <code>sort</code></p>

<pre><code>aaa
aba\nbbb
aba\nccc
ccc\naa    
</code></pre>

<p>and then restore new lines:</p>

<pre><code>aaa

aba
bbb

aba
ccc

ccc
aa    
</code></pre>