<p>I have a file temp.txt, that I want to sort with the <code>sort</code> command in bash.</p>

<p>I want the sorted results to replace the original file.</p>

<p>This doesn't work for example (I get an empty file):</p>

<pre><code>sortx temp.txt &gt; temp.txt
</code></pre>

<p>Can this be done in one line without resorting to copying to temporary files?</p>

<hr>

<p>EDIT: The <code>-o</code> option is very cool for <code>sort</code>. I used <code>sort</code> in my question as an example. I run into the same problem with other commands:</p>

<pre><code>uniq temp.txt &gt; temp.txt.
</code></pre>

<p>Is there a better general solution?</p>

Read up on the non-interactive editor,
```
ex
```
.