• 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: Graff <email@hidden>
  • Date: Sun, 21 Dec 2003 02:19:45 -0500

I changed it around a bit and this seems to work fine also:
sort -n -t '.' -k 1,1 -k 2,2 -k 3,3 -k 4,4 unsortedfile -o sortedfile

Not only that but it takes under 1 second to perform a sort on a file of 10,000 lines of 1 IP number per line. The best AppleScript sort implementation takes 72 seconds just for the sort, in addition to a minute or two for massaging the data to and from a format necessary for sorting. So I would estimate that doing it as a pure AppleScript as opposed to a "do shell script" would take a factor of at least 150 times as long for a list of 10,000 items.

I would say that if you are running Mac OS X then use "do shell script" to do the sorting. It is much simpler and faster than any other method I have seen:
------------
property FILE_NAME : "sorted"

set unsortedFile to choose file
set unsortedPOSIX to the quoted form of the POSIX path of unsortedFile

set baseWritefile to ((path to desktop) as text) & FILE_NAME
set writeFile to baseWritefile & ".txt"
set attemptNumber to 0
tell application "Finder"
repeat while (exists file writeFile)
set attemptNumber to attemptNumber + 1
set writeFile to baseWritefile & " - " & ((attemptNumber) as text) & ".txt"
end repeat
end tell

set sortedPOSIX to the quoted form of the POSIX path of writeFile

do shell script "sort -n -t '.' -k 1,1 -k 2,2 -k 3,3 -k 4,4 " & unsortedPOSIX & " -o " & sortedPOSIX
------------

- Ken

On Dec 21, 2003, at 12:12 AM, Deivy Petrescu wrote:

At 3:46 PM -0500 12/20/03, Graff wrote:
This will do it, it seems that you need to assign a start and an end to the keys:
sort -n -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n ~/Desktop/unsortedIP.txt -o ~/Desktop/sortedIP.txt

- Ken


I tried that but did not get the right end of fields for k. Actually, looking at them I would not have guessed.
Thanks a lot
_______________________________________________
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.

References: 
 >Re: Sorting IP addresses (From: Bill <email@hidden>)
 >Re: Sorting IP addresses (From: Emmanuel <email@hidden>)
 >Re: Sorting IP addresses (From: Deivy Petrescu <email@hidden>)
 >Re: Sorting IP addresses (From: Graff <email@hidden>)
 >Re: Sorting IP addresses (From: Deivy Petrescu <email@hidden>)

  • Prev by Date: Re: Match 'if' Condition and Do Nothing
  • Next by Date: Re: Write to file
  • Previous by thread: Re: Sorting IP addresses
  • Next by thread: Sorting IP addresses - Progress
  • Index(es):
    • Date
    • Thread