Hi everyone, I am looking for a script that sorts lines in a hosts file.
Some lines have "#" comments appended to the end of the line
describing the type of machine, location or application and
I really need to keep that info in the file. Here is a brief
sample of what I am dealing with.

One other thing I only have to sort one class C subnet,
therefore the sort can be isolated to the 4th octet.

<code> 10.194.196.46 chqnocp01 # Laser 4MV by Joe Blow
10.194.196.47 chqnocp02
10.194.196.49 nnocrpt01
10.194.196.50 nnocgw001
10.194.196.52 nnocs002
10.194.196.53 wslkms02 wslknms0
10.194.196.54 nnocws001
10.194.196.55 heckyll
10.194.196.57 txwl013w
10.194.196.61 krios
10.194.196.62 stasis # dial up server
10.194.196.63 nnocdts01 # sparc 5 in wan rm
10.194.196.64 saturn
10.194.196.65 libra
10.194.196.66 legato-school
10.194.196.67 txwlxdbs nnocs002a
<code>

thx

-mike


In reply to sorting /etc/hosts by tmbailey123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.