comm(1) comm(1)
NAME
comm - select or reject lines common to two sorted files
SYNOPSIS
comm [option] file1 file2
DESCRIPTION
comm compares two files in which the lines are sorted on the basis of
the currently valid collating sequence. Sorting can be performed with
the sort command [see sort(1)].
OPTIONS
No options specified:
comm produces three columns with the following meanings:
______________________________________________________________
| Column 1 | Column 2 | Column 3 |
|___________________|____________________|____________________|
| lines which occur | lines which occur | lines which occur |
| in file1 only | in file2 only | in both files |
|___________________|____________________|____________________|
-1 Column 1 is not output.
-2 Column 2 is not output.
-3 Column 3 is not output.
-12 comm outputs all lines common to both files.
-23 comm outputs all lines which only occur in file1
-13 comm outputs all lines which only occur in file2
-123 comm generates no output.
-- If file1 begins with a dash (-), the end of the command-line
options must be marked with --.
file1 file2
Names of the two sorted files which you want to compare.
The comm command will not function properly unless both files
have been sorted. If you use a dash as one of the names, comm
reads from standard input.
LOCALE
The LCMESSAGES environment variable governs the language in which
message texts are displayed.
The LCCOLLATE environment variable governs the collating sequence.
Page 1 Reliant UNIX 5.44 Printed 11/98
comm(1) comm(1)
If LCMESSAGES or LCCOLLATE is undefined or is defined as the null
string, it defaults to the value of LANG. If LANG is likewise unde-
fined or null, the system acts as if it were not internationalized.
If any of the locale variables has an invalid value, the system acts
as if none of the variables were set.
The LCALL environment variable governs the entire locale. LCALL
takes precedence over all the other environment variables which affect
internationalization.
EXAMPLES
The file books contains the titles of books and their authors. Each
line contains the title of one book and the name of its author, with a
space between them. You would now like to search the file books for a
number of authors whose names you have listed in the file authors1.
The contents of books and authors1 are as follows:
books authors1
"Gormenghast" Peake Blyton
"Buddenbrooks" Mann Gogol
"Noddy" Blyton Joyce
"Ulysses" Joyce Kafka
Mann
Tolstoy
You can now proceed as follows:
- Use awk to extract the authors from books.
- Sort the authors in books using sort.
- Redirect the output of sort to the new file authors2.
- Compare the files authors1 and authors2 using comm -2.
$ awk '{printf"%s\n",$2}' books | sort > authors2
The file authors2 contains the following:
Blyton
Joyce
Mann
Peake
Page 2 Reliant UNIX 5.44 Printed 11/98
comm(1) comm(1)
$ comm -2 authors1 authors2
Blyton
Gogol
Joyce
Kafka
Mann
Tolstoy
All authors which are only in authors1 are output in column 1. Then
come the contents of column 3, which lists all authors present in both
files.
SEE ALSO
cmp(1), diff(1), sort(1), uniq(1).
Page 3 Reliant UNIX 5.44 Printed 11/98