NAME
comm - Compares two sorted files
SYNOPSIS
comm [-123] file1 file2
The comm command reads file1 and file2 and writes three
columns to standard output, showing which lines are common
to the files and which are unique to each.
FLAGS
-1 Suppresses output of the first column (lines in file1
only).
-2 Suppresses output of the second column (lines in file2
only).
-3 Suppresses output of the third column (lines common to
file1 and file2).
comm -123 produces no output.
DESCRIPTION
The leftmost column of standard output includes lines that
are in file1 only. The middle column includes lines that
are in file2 only. The rightmost column includes lines that
are in both file1 and file2.
If you specify - (dash) in place of one of the filenames,
comm reads standard input.
The file1 and file2 arguments should be sorted according to
the collating sequence specified by the LC_COLLATE environ-
ment variable (see sort).
EXAMPLES
In the following examples, file1 contains the following
sorted list of North American cities:
Anaheim
Baltimore
Boston
Chicago
Cleveland
Dallas
Detroit
Kansas City
Milwaukee
Minneapolis
New York
Oakland
Seattle
Toronto
file2 contains this sorted list:
Atlanta
Chicago
Cincinnati
Houston
Los Angeles
Montreal
New York
Philadelphia
Pittsburgh
San Diego
San Francisco
St. Louis
1. To display the lines unique to each file and common to
the two files, enter:
comm file1 file2
This command results in the following output:
Anaheim
Atlanta
Baltimore
Boston
Chicago
Cincinnati
Cleveland
Dallas
Detroit
Houston
Kansas City
Los Angeles
Milwaukee
Minneapolis
Montreal
New York
Oakland
Philadelphia
Pittsburgh
San Diego
San Francisco
Seattle
St. Louis
Toronto
The leftmost column contains lines in file1 only, the
middle column contains lines in file2 only, and the
rightmost column contains lines common to both files.
2. To display any one or two of the three output columns,
include the appropriate flags to suppress the columns
you do not want. For example, the following command
displays lines that appear in file1 and in file2 only:
comm -3 file1 file2
Anaheim
Atlanta
Baltimore
Boston
Cincinnati
Cleveland
Dallas
Detroit
Houston
Kansas City
Los Angeles
Milwaukee
Minneapolis
Montreal
Oakland
Philadelphia
Pittsburgh
San Diego
San Francisco
Seattle
St. Louis
Toronto
3. The following command displays lines that appear in
file2 only:
comm -13 file1 file2
Atlanta
Cincinnati
Houston
Los Angeles
Montreal
Philadelphia
Pittsburgh
San Diego
San Francisco
St. Louis
4. The following command displays only those lines that
appear in both file1 and file2:
comm -12 file1 file2
Chicago
New York
RELATED INFORMATION
Commands: cmp(1), ctab(1), diff(1), sdiff(1), sort(1),
uniq(1).
Files: ctab(4).
"Using Internationalization Features" in the OSF/1 User's
Guide.
Acknowledgement and Disclaimer