title: Can I make this bash script that writes to multiple files run any faster?
body: <p>I have a script that reads in lines from a file, takes the first column of each line, and appends to a file named that line (I am trying to write many different files, named $id.txt). </p>
  
  <p>Is it possible to have a script that does anything faster than this (on a single-node machine)? Note that I use <code>read -r</code> and <code>id="$(echo $line | awk '{print $1}')"</code> because I have tab-separated fields and there are certain characters like backslashes in some fields that I want to keep.</p>
  
  <pre><code>    while read -r line
      do
          id="$(echo $line | awk '{print $1}')"
          echo "$line" &gt;&gt; $id.txt
      done &lt; $1
  </code></pre>
  
  <p>Some characteristics of my input:</p>
  
  <ul>
  <li>the output <code>$id.txt</code> files are not that large, usually a few hundred lines on average and up to a few thousand lines</li>
  <li>the id's are actually already sorted and the lines come in continuous blocks, i.e.:</li>
  </ul>
  
  <blockquote>
  <pre><code>abc ...
  abc ...
  def ...
  def ...
  def ...
  def ...
  ghi ...
  ghi ...
  </code></pre>
  </blockquote>