title: Sort very large text file in PowerShell
body: <p>I have standard Apache log files, between 500Mb and 2GB in size. I need to sort the lines in them (each line starts with a date yyyy-MM-dd hh:mm:ss, so no treatment necessary for sorting.</p>
  
  <p>The simplest and most obvious thing that comes to mind is</p>
  
  <pre><code> Get-Content unsorted.txt | sort | get-unique &gt; sorted.txt
  </code></pre>
  
  <p>I am guessing (without having tried it) that doing this using <code>Get-Content</code> would take forever in my 1GB files. I don't quite know my way around <code>System.IO.StreamReader</code>, but I'm curious if an efficient solution could be put together using that?</p>
  
  <p>Thanks to anyone who might have a more efficient idea.</p>
  
  <p>[edit]</p>
  
  <p>I tried this subsequently, and it took a very long time; some 10 minutes for 400MB.</p>