Sorting text files is a common task. The sort command sorts text files and stdin. It can be coupled with other commands to produce the required output. uniq is often used with sort to extract unique (or duplicate) lines. The following recipes illustrate some sort and uniq use cases.
Sorting unique and duplicate lines
Getting ready
The sort and uniq commands accept input as filenames or from stdin (standard input) and output the result by writing to stdout.
How to do it...
- We can sort a set of files (for example, file1.txt and file2.txt), like this:
$ sort file1.txt file2.txt > sorted.txt
Alternatively...