Skip to Content
Mac OS X in a Nutshell
book

Mac OS X in a Nutshell

by Jason McIntosh, Chuck Toporek, Chris Stone
January 2003
Intermediate to advanced
832 pages
32h 40m
English
O'Reilly Media, Inc.
Content preview from Mac OS X in a Nutshell

Name

uniq

Synopsis

uniq [options] [file1 [file2]]

Removes duplicate adjacent lines from sorted file1, sending one copy of each line to file2 (or to standard output). Often used as a filter. Specify only one of -c, -d, or -u. See also comm and sort.

Options

-c

Print each line once, counting instances of each.

-d

Print duplicate lines once, but no unique lines.

-f n

Ignore the first n fields of a line. Fields are separated by spaces or by tabs.

-s n

Ignore the first n characters of a field.

-u

Print only unique lines (no copy of duplicate entries is kept).

-n

Ignore the first n fields of a line. Fields are separated by spaces or by tabs.

+ n

Ignore the first n characters of a field. Both [-/+]n have been depricated but are still in this version.

Examples

Send one copy of each line from list to output file list.new (list must be sorted):

                     uniq list list.new

Show which names appear more than once:

                     sort names | uniq -d

Show which lines appear exactly three times:

                     sort names | uniq -c | awk '$1 =  = 3'
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mac OS X Internals: A Systems Approach

Mac OS X Internals: A Systems Approach

Amit Singh
C++ In a Nutshell

C++ In a Nutshell

Ray Lischner
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar
Optimized C++

Optimized C++

Kurt Guntheroth

Publisher Resources

ISBN: 0596003706Supplemental ContentCatalog PageErrata