• 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: Nigel Garvey <email@hidden>
  • Date: Fri, 19 Dec 2003 09:47:45 +0000

Marconi wrote on Thu, 18 Dec 2003 09:40:11 -0700:

>The answers thus far have not actually addresses the sorting but rather
>getting the IP addresses into a 'sortable' form. That is, rather than sort
>four times -- once for each quad -- convert the IPs into a more easily
>sorted form and sort just once. Of course, I need to preserve the original
>IPs as well, for display and writing to a file,

As a ready-made solution, the script I posted the other day which
imitates the OS X Finder's sort order for names with numeric components...

>Date: Tue, 16 Dec 2003 02:52:43 +0000
>From: Nigel Garvey <email@hidden>
>Subject: Re: Open Dialog Sort Order

... can obviously sort a list of IP address "numerically" too.

-- Usage demo
set addressText to "215.2.10.75
64.1.1.12
215.2.6.1
215.154.24.77"

-- Convert the text to a list
set addressList to addressText's paragraphs
-- Sort
FinderSort(addressList)

-- Convert back to a single text with delimiter return (or line feed)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return -- (or ASCII character
10)
set sortedText to addressList as string
set AppleScript's text item delimiters to astid

sortedText
-- "64.1.1.12
215.2.6.1
215.2.10.75
215.154.24.77"

>I would note that using ASCII means that I would need a case-sensitive
>sort, yes? Might be easier to stick with numbers.

Numeric characters only have one case, so it's feasible - and faster - to
do a case-sensitive sort on them. This is very easily achieved by calling
the sort in a 'considering case' block.

considering case
FinderSort(addressList)
end

NG
_______________________________________________
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.

  • Prev by Date: Re: Pinging
  • Next by Date: auto run a applescript and quitting it
  • Previous by thread: Re: Sorting IP addresses
  • Next by thread: Re: Sorting IP addresses
  • Index(es):
    • Date
    • Thread