Sort lines of a text file

The sort command is used to sort the lines of a text file in Linux. You can provide several command line options for sorting data in a text file.

Here is an example file:

To sort the file in alphabetical order, we can use the sort command without any options:

To sort in reverse, we can use the -r option:

To check if a file is already sorted, use sort with the -c option. This option also reports the first unsorted line:

Leave a Reply

Your email address will not be published. Required fields are marked *