title: Combining sorted files with fifos
body: <p>I have some sorted, gzipped files in a directory. How do I combine some of them into another sorted, gzipped file? Right now I'm using explicit fifos. Is there a way to do it in bash without? I'm a bit of a bash noob, so please excuse my lack of style.</p>
  
  <pre><code>#!/bin/bash
  # Invocation ./merge [files ... ]
  # Turns an arbitrary set of sorted, gzipped files into a single sorted, gzipped file,
  # printed to stdout. Redirect this script's output!
  for f in $@
  do
      mkfifo $f.raw
      gzcat $f &gt; $f.raw &amp;
      # sort -C $f.raw
  done
  sort -mu *.raw | gzip -c # prints to stdout.
  rm -f *.raw
  </code></pre>
  
  <p>I'm looking to convert this into something like...</p>
  
  <pre><code>sort -mu &lt;(gzcat $1) &lt;(gzcat $2) &lt;(gzcat $3) ... | gzip -9c # prints to stdout.
  </code></pre>
  
  <p>...but don't know how. Do I need a loop building the parameters to string? Is there some sort of magic shortcut for this? Maybe <code>map gzcat $@</code>?</p>
  
  <p>NOTE: Each of the files is in excess of 10GB (and 100GB unzipped). I have a 2TB drive, so this isn't really a problem. Also, this program MUST run in O(n) or it becomes unfeasible.</p>