Sort command in the unix system sorts the contents of the text file line by line. Sort is a simple and very useful command which will rearrange the lines in a text file so that they are sorted, numerically and alphabetically.
The basic syntax of sort command is

The options are
Consider below text file as input.
> cat data.txt
Unix 01 machine
Linux 03 server
Unix 05 os
Unix 01machine
Linux 03 server
Unix 01 machine
Unix 01 machine
Unix 05 os
Linux 03 server
Unix 01 machine
Unix 05 os
> sort -n data.txt
Unix 01 machine
Unix 01 machine
Linux 03 server
Unix 05 os
>sort -nr data.txt
Unix 05 machine
Linux 03 server
Unix 01 machine
Unix 01 machine
The basic syntax of sort command is

The options are
- -b : Ignores leading spaces in each line
- -c : Check for sorted input, but do not sort.
- -d : Uses dictionary sort order. Conisders only spaces and alphanumeric characters in
- -f : Uses case insensitive sorting.
- -m : Merge already sorted files.
- -M : Sorts based on months. Considers only first 3 letters as month. Eg: JAN, FEB
- -n : Uses numeric sorting
- -R : Sorts the input file randomly.
- -r : Reverse order sorting
- -k : Sorts file based on the data in the specified field positions.
- -u : Suppresses duplicate lines
- -t : input field separator
Consider below text file as input.
> cat data.txt
Unix 01 machine
Linux 03 server
Unix 05 os
Unix 01machine
- Sorting the text
Linux 03 server
Unix 01 machine
Unix 01 machine
Unix 05 os
- Eliminate Duplicates
Linux 03 server
Unix 01 machine
Unix 05 os
- Numeric sorting
> sort -n data.txt
Unix 01 machine
Unix 01 machine
Linux 03 server
Unix 05 os
- Sort the data in reverse order
>sort -nr data.txt
Unix 05 machine
Linux 03 server
Unix 01 machine
Unix 01 machine