todo/sorted .mrconfigmyreposhttp://myrepos.branchable.com/todo/sorted_.mrconfig/myreposikiwiki2019-12-02T03:09:58ZAlternative Sorting Method with GAWKhttp://myrepos.branchable.com/todo/sorted_.mrconfig/comment_1_fe128f2a8f16438b9e5b48fcfaf0c47b/hello2019-12-02T03:09:58Z2018-10-01T23:51:42Z
<p>I am by no way a command line expert, but I was unable to get the sort-ini method to work for me so I looked into generalized sorting by pattern and came across a site that had an example that was pretty close to what I needed.</p>
<p>A couple of paragraphs down the original example is labeled "Robbins' awk based shell pipeline"</p>
<p>https://homepage.smc.edu/morgan_david/linadmin/labs/sort-multiline-blocks.htm</p>
<p>From there I came to this</p>
<pre><code>gawk -v RS="" '{ gsub("\n", "###"); print }' .mrconfig | sort -f | gawk -v ORS="\n\n" '{ gsub("###", "\n"); print }' > .mrconfig.tmp && mv .mrconfig.tmp .mrconfig
</code></pre>
<p>The <code>###</code> is my temp replacement for the newline so that sort can be used, at which point it is returned to a newline. I had trouble with the <code>^Z</code> characters in the example.</p>
<p>Which I then set up as an alias</p>
<pre><code>alias mrsort="gawk -v RS=\"\" '{ gsub(\"\n\", \"###\"); print }' .mrconfig | sort -f | gawk -v ORS=\"\n\n\" '{ gsub(\"###\", \"\n\"); print }' > .mrconfig.tmp && mv .mrconfig.tmp .mrconfig"
</code></pre>