title: How to ensure file written with sed w command is closed
body: <p>I'm using the sed 'w' command to get the labels from a TeX document using:</p>
  
  <pre><code>/\\label{[a-zA-Z0-9]*}/w labels.list
  </code></pre>
  
  <p>This script is part of a pipeline in which, later on, awk reads the file that sed has just written. e.g</p>
  
  <pre><code>cat bob | sed -f sedScript | awk -f awkScript labels.list -
  </code></pre>
  
  <p>Sometimes the pipeline produces the correct output, sometimes it doesn't (for exactly the same input file 'bob'). It's random.</p>
  
  <p>I can only conclude that sometimes awk tries to read the file before sed has closed it properly. Is there anyway I can force sed to close the file at the end of the script, or any other suggestions as to what the problem may be?</p>