title: Locking output file for shell script invoked multiple times in parallel
body: <p>I have close to a million files over which I want to run a shell script and append the result to a single file.  </p>
  
  <p>For example suppose I just want to run <code>wc</code> on the files.
  So that it runs fast I can parallelize it with <code>xargs</code>. But I do not want the scripts to step over each other when writing the output. It is probably better to write to a few separate files rather than one and then <code>cat</code> them later.  But I still want the number of such temporary output files to be significantly smaller than the number of input files. Is there a way to get the kind of locking I want, or is it the case that is always ensured by default?</p>
  
  <p>Is there any utility that will recursively <code>cat</code> two files in parallel?  </p>
  
  <p>I can write a script to do that, but have to deal with the temporaries and clean up. So was wondering if there is an utility which does that.</p>