• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sorting IP addresses
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting IP addresses


  • Subject: Re: Sorting IP addresses
  • From: Christopher Stone <email@hidden>
  • Date: Sat, 20 Dec 2003 04:06:33 -0600

At 07:37 -0700 12/17/2003, Marconi wrought:

Given a list of IP addresses, I need to sort them in proper (ascending) order. That is, I need a routine which knows that 205.192.32.45 comes AFTER 65.163.82.130 and so forth.

I think the key would be setting text item delimiters to a period and then sorting on each quad.

Can anyone help me out? (I'm going to be doing this in BBEdit.)
______________________________________________________________________

Well. If you're going to be using BBEdit anyway, why not just use the built-in facility for this type of thing? BBEdit 7 makes it dead simple, and much more sophisticated table-type sorting is possible using regular expressions.

Over a twenty run test with 2000 lines of data the average sort time was 0.32 seconds. I used Smile 2.5.9 and its "chrono" property to do the timing.

BBEdit 7.1.1
Mac OS 10.3.2
Dual 867 G4 Mac


set someData to "166.78.247.22
205.158.62.24
202.156.235.48
62.78.76.79
62.78.76.80
69.84.204.85
24.203.236.101
24.203.237.101
217.81.172.103
61.116.186.110
217.117.136.154
217.117.136.155
16.208.21.156
16.208.22.156
63.138.247.187
202.175.98.191
0.57.7.195
180.248.136.220
24.47.176.225
214.240.46.232
4.176.70.236
24.31.170.237"

tell application "BBEdit"
set ntw to make new window with properties {name:"tempSortData", contents:someData}
if exists of front text window then
tell ntw
set someDataSorted to sort lines sort options {sort digits numerically:true} output options {returning results:true}
close without saving
end tell
end if
end tell

someDataSorted

(*
0.57.7.195
4.176.70.236
16.208.21.156
16.208.22.156
24.31.170.237
24.47.176.225
24.203.236.101
24.203.237.101
61.116.186.110
62.78.76.79
62.78.76.80
63.138.247.187
69.84.204.85
166.78.247.22
180.248.136.220
202.156.235.48
202.175.98.191
205.158.62.24
214.240.46.232
217.81.172.103
217.117.136.154
217.117.136.155
*)


Chris
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Sorting IP addresses
      • From: Christopher Stone <email@hidden>
References: 
 >Sorting IP addresses (From: Marconi <email@hidden>)

  • Prev by Date: WebDAV
  • Next by Date: Re: Sorting IP addresses
  • Previous by thread: Re: Sorting IP addresses
  • Next by thread: Re: Sorting IP addresses
  • Index(es):
    • Date
    • Thread