What is the UNIX sort command?

The sort command is used to sort a complete file by arranging the records in a specific order. By default, the sort command sorts files assuming that the contents are ASCII characters. The file is sorted line by line​, and the blank space is used as the field separator. The following slides will explain the sort command better.

Example

Suppose there exists a "file.txt" with a few names of the students enrolled in a music class. The sort command is used to sort all the names in the file.

The file contains these names in the following order:

Wayne

George

Alex

Brandon

Cooper

Tom

svg viewer

Code

To sort these names, run the following code:

main.sh
file.txt
sort file.txt
Copyright ©2024 Educative, Inc. All rights reserved