title: How do I let sed 'w' command know where the filename ends?
body: <p>Every example I was able to find demonstrating the <code>w</code> command of <code>sed</code> has it in the end of the script. What if I can't do that?</p>
  
  <p>An example will probably demonstrate the problem better:</p>
  
  <pre class="lang-none prettyprint-override"><code>$ echo '123' | sed 'w tempfile; s/[0-9]/\./g'
  sed: couldn't open file tempfile; s/[0-9]/\./g: No such file or directory
  </code></pre>
  
  <p>(How) can I change the above so that <code>sed</code> knows where the filename ends?</p>
  
  <p>P.S. I'm aware that I can do</p>
  
  <pre><code>$ echo '123' | sed 'w tempfile
  &gt; s/[0-9]/\./g'
  ...
  </code></pre>
  
  <p>Are there prettier options?</p>
  
  <p>P.P.S. People tend to suggest to split it in two scripts. The question is then: is it safe? What if I was going to branch somewhere after the <code>w</code> command, and so on. Can someone confirm that <em>any</em> script can be split in two after <em>any</em> command and that will not affect the results?</p>
  
  <p><strong>Final edit:</strong> I checked that multiple <code>-e</code> work just as concatenated commands. I thought it was more complex (like the first one should always exit before the second one starts, etc.). However, I tried splitting a <code>{..}</code> block of commands between two scripts and it still worked, so the <code>w</code> thing is really not a serious problem. Thanks to all.</p>