This is a small tutorial on how to use sort command to sort a file. Sorting is very useful when dealing with DB files, CSV, xls, log files in fact a text file too. By default sort command will sort according to alphabets. First sort tries to sort according to single character, if it finds the first character same in two lines, then it moves to sort second character. Suppose I have a following word list in a file
cat filename.txt
abc
cde
hij
klm
kle
ble
abc
cde
hij
klm
kle
ble
This will be sorted first with first char. When it finds both the char same in this example klm and kle start with same characters, so it tries to sort with third character which is different in them. The output of sort as below
sort filename.txt
abc
ble
cde
hij
kle
klm