Jump to content

Uniq

From Niidae Wiki

Template:Short description Template:About Template:Lowercase title Template:Infobox software uniq is a utility command on Unix, Plan 9, Inferno, and Unix-like operating systems which, when fed a text file or standard input, outputs the text with adjacent identical lines collapsed to one, unique line of text.

Overview

[edit]

The command is a kind of filter program. Typically it is used after sort. It can also output only the duplicate lines (with the -d option), or add the number of occurrences of each line (with the -c option). For example, the following command lists the unique lines in a file, sorted by the number of times each occurs:

<syntaxhighlight lang="sh"> $ sort file | uniq -c | sort -n </syntaxhighlight>

Using uniq like this is common when building pipelines in shell scripts.

History

[edit]

First appearing in Version 3 Unix,<ref name="reader">Template:Cite tech report</ref> uniq is now available for a number of different Unix and Unix-like operating systems. It is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX and the Single Unix Specification.<ref>Template:Man</ref>

The version bundled in GNU coreutils was written by Richard Stallman and David MacKenzie.<ref>Template:Man</ref>

A uniq command is also part of ASCII's MSX-DOS2 Tools for MSX-DOS version 2.<ref>MSX-DOS2 Tools User's Manual by ASCII Corporation</ref>

The command is available as a separate package for Microsoft Windows as part of the GnuWin32 project<ref>CoreUtils for Windows</ref> and the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.<ref>Native Win32 ports of some GNU utilities</ref>

The Template:Mono command has also been ported to the IBM i operating system.<ref>Template:Cite web</ref>

See also

[edit]

References

[edit]

Template:Reflist

[edit]

Template:Wikibooks

Template:Unix commands Template:Plan 9 commands Template:Core Utilities commands