title: One line sed command in OS X : replace a specific line
body: <p>I want to replace the second line of my <code>sample.txt</code> file by the text <code>4 5 6</code>. In Linux I use:</p>
  <pre><code>sed '2,2c\4 5 6' sample.txt
  </code></pre>
  <p>However, in Mac OS X, this does not work. A workaround of this problem is to write a script where the replacing text should be kept in a newline:</p>
  <pre><code>#!/bin/sh
  sed -e &quot;2,2c\\
  4 5 6&quot; sample.txt
  </code></pre>
  <p>N.B. <code>-e</code> and double quote <code>&quot; &quot;</code> are important here (I don't know why).</p>
  <p>My question is, can I merge the script into a single line command?*</p>
  <p>This would be useful when I want to use this as a command in a program, say in Fortran.</p>
  <p>I am not willing to install <code>gnu-sed</code>.</p>
  <p>Let me summarize once again:</p>
  <p><code>cat sample.txt</code> yields</p>
  <pre><code>1 2 3
  1 2 3
  7 8 9
  </code></pre>
  <p>Using a single line command, I want to modify the file's content as:</p>
  <pre><code>1 2 3
  4 5 6
  7 8 9
  </code></pre>