Here are some shell commands that I find very helpful. Chances are you will end up saving a lot of time if you know how to use them properly.

Sort a file :
sort filename.dat > newfilename.dat

If you have numbers instead of characters in the file, then :
sort -n filename.dat > newfilename.dat

sort -n -r filename.dat > newfilename.dat
This will sort the file in reverse order

If your file has multiple fields and you want to sort based on the second field then:
sort -n +1 filename.dat > newfilename.dat

Find Union,Intersection or Difference of Files
Union of two files :
sort file1 file2 | uniq > union_file
Intersection of two files :
sort file1 file2 | uniq -d > intersection_file
Difference of two files :
sort file1 file2 | uniq -u > difference_file