Showing posts with label E-Linux. Show all posts
Showing posts with label E-Linux. Show all posts

Thursday, March 1, 2012

Sort IP Addresses with GNU sort

How to sort IP addresses using the GNU sort utility.

The short answer. Here’s the invocation that works. It’s explained in the long answer that follows.
sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4

The long answer. More than once I’ve been confronted with a list of IP addresses that I’ve wanted to sort into numeric order. Trouble is, the dotted-quad notation isn’t sort-friendly. Consider the following raw list of addresses.
$ cat addresses.txt
129.95.30.40
5.24.69.2
19.20.203.5
1.2.3.4
19.20.21.22
5.220.100.50

Without options, sort will rely on alphabetic order, which certainly won’t do what you want:
$ sort addresses.txt
1.2.3.4
129.95.30.40
19.20.203.5
19.20.21.22
5.220.100.50
5.24.69.2
There are so many mistakes in this ordering I’m not even going to try to list them all.
The situation is only marginally improved when using the --numeric-sort (-n) option.
$ sort -n addresses.txt
1.2.3.4
5.220.100.50
5.24.69.2
19.20.203.5
19.20.21.22
129.95.30.40

The first set of numbers in each dotted-quad sort correctly—5 preceeds 19, and 129 is at the tail end—but the internal numbering still gets improper treatment. 5.220.100.50 is listed prior to 5.24.69.2 because 220 is alphabetically prior to 24. Likewise the two19.20.x.x addresses are mixed up because 203 is alphabetically prior to 21.
The solution is to tell sort to order the list numerically, considering each address as a set of four numeric fields, each separated by a dot.
$ sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 addresses.txt
1.2.3.4
5.24.69.2
5.220.100.50
19.20.21.22
19.20.203.5
129.95.30.40

In English, you’re saying, Yo, sort! I’ve got here a list of numbers (-n), but each item in the list consists of some subnumbers, fields set apart from the others by a dot (-t .). Sort first by the first field, and only the first field (-k 1,1), then by the second and only the second (-k 2,2), and so on (-k 3,3 -k 4,4).




.
Read More

Monday, September 19, 2011

How to colorize your log files with CCZE

Read More

Tuesday, January 25, 2011

Catatan Mikrotik

Moving a Simple Queue to position 0 via a script

/ip firewall mangle move [ /ip firewall mangle find chain="forward" dynamic=yes] 0

or

/queue simple move [/queue simple find name="Limit p2p"] 0

Sumber
Read More

Saturday, January 15, 2011

Tips Monitoring Squid Proxy

squidclient -h host -p 80 mgr:info
squidclient -h host -p 80 mgr:counters
squidclient -h host -p 80 mgr:utilization
squidclient -h host -p 80 mgr:5min
squidclient -h host -p 80 mgr:60min
squidclient -h host -p 80 mgr:mem

untuk proxy di localhost, perintahnya diganti dengan

misal:

squidclient mgr:info

Untuk melihat option mgr: yang lain ketik
squidclient mgr:
Read More

Tuesday, June 22, 2010

Server repository Indonesia

Read More

Saturday, January 1, 2005

E-Linux

E-Linux
Read More