Introduction to UNIX for Web Developers The "uniq" Utility Like the comm utility, the "uniq" utility is used to find repetition. However, the "uniq" utility is used to find repeated lines within a file rather than between two files. The "uniq" utility is used to find adjacent duplicate lines and (usually) remove them. The usual syntax looks something like

uniq options filename optional_new_filename

If no optional_new_filename is specified, the output of uniq will be printed to standard output.

As you might expect, it is most common to run the uniq utility after having already sorted the file. Below is an example on how you might use the "uniq" utility.

[uniq Example]

The "uniq" utility comes with several useful utilities. The more common ones are described below

Option Explanation
-c Produces a columnar output in which the left column reports the number of times the line was repeated
-d Displays one copy of each repeated line, but does not display non- repeated lines.
-u Non repeated lines are displayed, but repeated lines are not.

Consider the following examples

[uniq Options Example]

Previous | Next | Table of Contents