comm - Unix, Linux Command


Advertisements

Previous Page
Next Page  
 

NAME

comm - The comm command compares two sorted files line by line.

SYNOPSIS

comm [OPTION]... FILE1 FILE2

DESCRIPTION

The comm command compares two sorted files line by line. With no options, comm produces three-column output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files. Each of these columns can be suppressed individually with options. It also supports suppressing column outputs and comparing lines without case sensitivity. To compare two files line by line using comm it is a prerequisite that files are first sorted.

Options

Tag Description
-1 suppress column 1 (lines unique to FILE1)
-2 suppress column 2 (lines unique to FILE2)
-3 suppress column 3 (lines that appear in both files)
--check-order check that the input is correctly sorted, even if all input lines are pairable
--nocheck-order do not check that the input is correctly sorted
--output-delimiter=STR separate columns with string STR
--help display a help message, and exit.
--version output version information, and exit.

EXAMPLES

EXAMPLE-1:

Lets say we have two files file1 and file2 .

file1: 1 2 3 4 5    and

file2: 2 3 4 8 9 

We can see the two files are different, but many of the lines are the same.If we run the comm command on the two files, it will read both files and give us three columns of output:

$ comm file1 file2
output: 1 2 3 4 5 8 9 Here, each line of output has either zero, one, or two tabs at the beginning, separating the output into three columns

EXAMPLE-2:

To supress column1 use -1 option:

$ comm -1 file1 file2
output: 2 3 4 8 9

EXAMPLE-3:

To supress column2 use -2 option:

$ comm -2 file1 file2
output: 1 2 3 4 5

EXAMPLE-4:

 To supress column3 use -3 option:

$comm -3 file1 file2
output: 1 5 8 9

EXAMPLE-5:

To check that the input is correctly sorted, even if all input lines are pairable.

~$ cat system_2
liine
line 3
line4

~$ cat xyz
line 1
line 2
line 3
line 4
line 6
line 6

$ comm system_2  xyz  --check-order

output:

liine
line 1
line 2
line 3
line4
line 4
line 6
line 6
comm: file 2 is not in sorted order

 


Previous Page
Next Page