sorting code for UNIX