Advanced sort question

Im trying to sort file names alphabetically. But I need to sort them based on the characters following the last _ in a file name.

Example

xfwis_001.jpg
jfiels_002.jpg
erwui_003.jpg

I will always have a _ followed by a 3 digit number at the end of the file name. This is what I need to sort on.

The sort method I want to use is the Unix one for performance reasons, but I don’t know if I can tell it to only look at the characters after the underscore.

Any ideas how I would do this?

This is what I have as a sort currently.


set old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10}
set list_string to (the_list as string)
set new_string to do shell script "echo " & quoted form of list_string & " | sort -f"
set new_list to (paragraphs of new_string)
set AppleScript's text item delimiters to old_delims
return new_list

Browser: Firefox 3.6.12
Operating System: Mac OS X (10.6)

Hi.

This seems to be it. Set the field separator to the underscore and sort on the second field:

set old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10} -- or {linefeed} now.
set list_string to (the_list as string)
set new_string to do shell script "echo " & quoted form of list_string & " | sort -f -t '_'  -k 2"
set new_list to (paragraphs of new_string)
set AppleScript's text item delimiters to old_delims
return new_list

Thanks alot, works like a charm:D