Sorting files is important for meaningful output and is useful while dealing with DB files, CSV, xls, log files and text files. By default, the sort command will sort according to alpha-bates, sorting according to single character vertically. If it finds the same character in two lines, then it will move on to sort the second character.
There are 9 ways to do that according to www.linuxnix.com. You can mix and match them as per your requirement.
• 1:To sorting file names according to alpha-bates: sort filename.txt.
• 2: If you have a file with host names in the third column, to sort it according to the column, use K for sorting that. Like, sort k3 filename.txt.
• 3: To sort/ etc/password file according to home directories, sort will by default take space/tabs as field separators. In etc/passwd file, the field separator is : and this can be done with t option. sort -t: -k6 /etc/passwd
• 4: To sort according to number, etc/passwd file according to UID, use -n option to do that. Sort will not understand numbers by default, so, use -n to make sure sort command understands it.sort -n -t: -k3 /etc/passwd. Without -n option sort will by default sort only first numerical char.