Sorting File Contents in Order

Sorting file contents via command line interface.



It is used to sort a program or file that is given in its input.


sort [option] filename


Option Description
-o To write the output to a new file.
-r To sort in reverse order.
-n To sort a file numerically.
-nr To sort a file with numeric data in reverse order.
-k To sort a table on the basis of any column number.
-c To check if the file given is already sorted or not.
-u To sort and remove duplicates


  • To simply sort a file:
sort myfile.txt

Get hands-on with 1200+ tech skills courses.