title: Mixed lexicographic and numeric sorting
body: <p>I have a list such as:</p>
  
  <h2>input.txt</h2>
  
  <pre><code>foo.bar.1
  foo.bar.2
  foo.bar.3.x.y.z
  foo.bar.10
  foo.bar.0
  baz.10.qux
  baz.3.qux
  </code></pre>
  
  <p>that needed to be sorted. I need to treat this as a dot separated
  fields, where numeric fields are needed to be sorted numerically.</p>
  
  <p>So I wrote:</p>
  
  <h2>mixsort.py</h2>
  
  <pre><code>#!/usr/bin/env python
  import sys
  seq = map(lambda l: map(lambda s: (s.isdigit() and [int(s)] or [s])[0], l),
            [ s.rstrip().split('.') for s in sys.stdin.readlines() ])
  seq.sort()
  sys.stdout.write( '\n'.join(['.'.join([str(i) for i in l]) for l in seq]) )
  </code></pre>
  
  <h2>usage</h2>
  
  <pre><code>$ mixsort.py &lt; input.txt
  baz.3.qux
  baz.10.qux
  foo.bar.0
  foo.bar.1
  foo.bar.2
  foo.bar.3.x.y.z
  foo.bar.10
  </code></pre>
  
  <p>But am I re-inventing the wheel here? Is there a common
  *nix utility that do what I need? is there a switch to <code>sort(1)</code> that
  will help me out. (note that the position of the numeric fields is
  unknown). Is there a better way to do the same thing?</p>