![]() |
Sort App (word, excell) or Unix or.....
I maintain a number of host tables that are Vi edited.
A number of them are unruly and need to be sorted by IP. Every method I have tried does not work with IPS I am trying to sort. The Sort commands all seem to ignore anything that comes after the periods in IP Addresses. e.g. 204.80.70 seems just fine to sort coming after 204.6.80.200? Any suggestions for app or methodology or command that likes ips or Decimals. At the moment I am brute forcing as the tables are about 85 percent sorted anyway. Thnax in advance. |
An awk wizard can probably help you with this. You might want to post in the unix forum in case none of them see it here.
|
the unix command 'sort' seems do this ... if you can't get it to work, maybe use 'man sort' and find a switch that might help
Code:
[v:~] v% cat t |
I assume you want this:
Code:
1.1.1.1Code:
1.1.1.1Code:
#! /usr/bin/perl |
although i'm not sure it's technically correct, this command gives the same output as above
Code:
sort -t . -n +1 filename |
Thanx
I will try....
If I were to use thee non Perl are you saying to do sort -t . -n +1 +2+3+4 filename or sort -t . -n +1 sort -t . -n +2 sort -t . -n +3 sort -t . -n +4 I would think the latter would mess up the sequence. If it makes a difference were talking about 20 Subnets within one file. |
this seemed to work,
Code:
sort -t . -n +1 filenameCode:
sort -t . -n +1 +2 +3 +4 filenametry the first line above, if it doesn't work, the second ... if not ... the perl code should work! |
ok with spaces:)
I'll try
|
just use the first one, here is an excerpt from 'man sort'
Quote:
good code: Code:
sort -t . -n +1 filename |
Argh, my code is wrong too. But the sort answer does not work either. A good data set is
Code:
1.1.1.1Code:
$ sort -t . -n +1 xCode:
$ ipsort x |
This has it:
Code:
#! /usr/bin/perlCode:
1.1.1.1 |
ah ha! try this one, found it using google:
Code:
file |
Thanx
Host table is @ work so to it in the am.
Thanx two you do I have 3 ways again:) On the non Perl any Idea of advantage of one of the other: example$ sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /etc/hosts example$ sort -t . +0 -1n +1 -2n +2 -3n +3 -4n /etc/hosts |
Forgot I had emailed myself one of the host tables
The command runs but does not sort properly, weird.
example$ sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /etc/hosts example$ sort -t . +0 -1n +1 -2n +2 -3n +3 -4n /etc/host Off to Perl :) :) I lied it worked fine.******** Thanx |
Stenter I do not know Perl
In your example where is the file name dir/path info?
Did I miss it? Can I just run it from Terminal? And can I save the output from there? |
Ahh, I got so caught up in sorting IPs that I forgot it is a hosts file you are working on. Give me a minute....
|
OK, here you go. It assumes lines are of the form "IPaddress name(s)" and discards other lines (ie comments)
Simply put this into a file, 'chmod 755 filename' and runit either as: ./filename /path/to/hosts >/path/to/OUTPUTFILE or ./filename </path/to/hosts >/path/to/OUTPUTFILE I am just starting to use perl, I am a sed/awk/sh type myself, so there are probably better ways of doing this... Code:
#! /usr/bin/perl |
Re: Stenter I do not know Perl
Quote:
Code:
example$ sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /etc/hosts > /path/to/file/to/save |
I ended up just saving as from Terminal window:)
And thank you both for all your hard work.
It is neat to have the syntex to auto output it to a file. I have not had a chance ot try Stenter's Perl yet. Even with Ips Sorted it took 8 hours straight to clean up that 30 Page host table, Phew. I Ended up Adding Every "unused" IP from Every segment that was missing and listing each as "Open" or "In Use?" (Scummed/not Documented). Now we can decide how many more VLans we need for our new sytstems. And at the same time play detective on the "In Use?" (Scummed/not Documented). ones. |
Yeah, been there done that....
Best to keep a DB with allocated IPs and only allow allocated IPs on the network. People think I am a network nazi, but you only have to go through what you did once or twice before you decide to get tough! :) |
Yeah in my home I go the next level MAC Address verification on who can be on the net
Unfortunately @ work I am the Systems Manager of Chain of Hospitals Radiology Departments not the Network Manager and to boot this group is Radioloy, not IT.
Even if they were willing to not route IPS that we have not "accounted" for It would be too cubersome. It is difficult enough to get connections Punched and trouble shoot net problems that arrise in our extensive sites. It is tempting though:) |
| All times are GMT -5. The time now is 04:05 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.