Ignore optional leading string when sorting
<p>Is there an efficient way to sort a file while ignoring a string that appears at the beginning of some lines?</p>

<p>For example, say I have a list of files like this:</p>

<pre><code>FileAardvark
FileBee
N-FileBear
N-FileCat
FileZebra
</code></pre>

<p>And I want to sort while ignoring the "N-", so the sorted result would be</p>

<pre><code>FileAardvark
N-FileBear
FileBee
N-FileCat
FileZebra
</code></pre>

<p>I need to not edit the lines directly, otherwise I could just strip the 'N-' from the file entirely. My initial thought was to use 'N-' as a delimiter to <code>sort</code>, but that fails both because 'N-' is multiple characters and because then the column number I need then differs from line to line.</p>

<p>In my particular case, it happened that all the strings started with the same term (i.e., as in the example, everything has "File" at the beginning) and I needed to sort on the entirety of the remaining line, so I ended up using this <code>sed</code>/<code>sort</code> chain, which got me the result I wanted:</p>

<p><code>sed -e 's/File/\x06/g' | sort -t$'\x06' -k2 | sed -e 's/\x06/File/g'</code></p>

<p>However, I can't depend on having a duplicated sequence at the beginning of all the strings relevant to the sorting, so how can I accomplish this in a more general way?    </p>