Sorting, unique and duplicates

Sorting is a common task that we always encounter with text files. Hence, in text processing tasks, sort is very useful. sort commands help us to perform sort operations over text files and stdin. Most often, it can also be coupled with many other commands to produce the required output. uniq is another command that is often used along with a sort command. It helps to extract unique lines from a text or stdin. sort and uniq can be coupled to find duplicates. This recipe illustrates most of the use cases with sort and uniq commands.

Getting ready

The sort command accepts input as filenames as well as from stdin (Standard input) and outputs the result by writing into stdout. The uniq command follows the same sequence ...

Get Linux Shell Scripting Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.