

Sort simply reorders the list alphabetically and outputs the sorted list to the standard output. Joni Governor Reorder Lists with sort $ sort names-list.txt The examples in this section will use the following text file as an input: Because uniq only removes identical adjacent lines, it is often used in conjunction with sort to remove non-adjacent duplicate lines. The uniq command takes input and removes repeated lines. Here, the sorted output is written to the ~/retired-roster.txt file. To write this content to a file, redirect the output as in the following example: grep -i "retired" ~/roster.txt | sort > ~/retired-roster.txt In the default configuration, this sort prints the output on the terminal. These results are sent to sort, which reorders this output alphabetically. This uses grep to filter the ~/roster.txt file for the string retired, regardless of case. Sort also accepts input from other commands as in the following example: grep -i "retired" ~/roster.txt | sort sort commands take the following format: sort ~/roster.txt Sorted text is sent to standard output and printed on the terminal unless redirected. The sort command accepts input from a text file or standard output, sorts the input by line, and outputs the result. Though narrow in their focus, both of these tools are useful in a number of different command line operations. The uniq command takes a list of items and removes adjacent duplicate lines. The sort command takes a list of items and sorts them alphabetically and numerically. The Linux utilities sort and uniq are useful for ordering and manipulating data in text files and as part of shell scripting.
