Sorting unique and duplicates
Sorting is a common task that we can encounter with text files. The sort
command helps 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 (or duplicate) lines from a text or stdin
. 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 same applies to the uniq
command.
How to do it...
- We can easily sort a given set of files (for example,
file1.txt
andfile2.txt ...
Get Linux Shell Scripting Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.