• 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: Sort a List with Integers & Letters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sort a List with Integers & Letters


  • Subject: Re: Sort a List with Integers & Letters
  • From: Steven Valenti <email@hidden>
  • Date: Tue, 3 Apr 2007 11:05:56 -0400

I'd like to work this out but I don't know much shell scripting. My actual code needs to sort a list of a list of records written to a database every time a new item is added.
The list will look more like this with a lot more record properties...
set theList to {{ModelNumber:"1610G", ModelName:"Gold Plate"}, {ModelNumber:"121ZB", ModelName:"Zip Guard"}, {ModelNumber:"114", ModelName:"White Matte"}} & ¬
{{ModelNumber:"13", ModelName:"Sterling Silver"}, {ModelNumber:"21124", ModelName:"Blueberry"}, {ModelNumber:"121FB", ModelName:"Flat Bottom"}}
I want to sort the list by the ModelNumber. Is there a way to sort this with a shell script. Sorry for not giving all the details from the start. I was going to work out the record part if I knew a way with a list.


Thanks,
Steven




Does this help?

set theList to {"1610G", "121ZB", "114", "13", "21124", "121FB", "250G", "240.25", "1610", "15", "240 25", "240"}

set AppleScript's text item delimiters to {ASCII character 10}
set theList to theList as Unicode text
set AppleScript's text item delimiters to {""}

set sortList to paragraphs of (do shell script "echo '" & theList & "' | sort -n -")

--> {"13", "15", "114", "121FB", "121ZB", "240", "240 25", "240.25", "250G", "1610", "1610G", "21124"}

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Prev by Date: Re: Sort a List with Integers & Letters
  • Next by Date: Re: Sort a List with Integers & Letters
  • Previous by thread: Re: Sort a List with Integers & Letters
  • Next by thread: Re: Sort a List with Integers & Letters
  • Index(es):
    • Date
    • Thread