Linux comm Command
The Linux comm command is used to compare two sorted files.
This command compares two sorted files line by line and displays the results. If no parameters are specified, the results are divided into three columns: the first column shows lines unique to the first file, the second column shows lines unique to the second file, and the third column shows lines common to both files. If the filename is -
, the comm command will read data from the standard input device.
Syntax
comm [-123][--help][--version][file1][file2]
Parameters:
-1 Do not show lines unique to the first file.
-2 Do not show lines unique to the second file.
-3 Do not show lines common to both files.
--help Display online help.
--version Show version information.
Example
The contents of aaa.txt and bbb.txt are as follows:
[root@localhost text]# cat aaa.txt
aaa
bbb
ccc
ddd
eee
111
222
[root@localhost text]# cat bbb.txt
bbb
ccc
aaa
hhh
ttt
jjj
Executing the comm command produces the following output:
[root@localhost text]# comm aaa.txt bbb.txt
aaa
bbb
ccc
aaa
ddd
eee
111
222
hhh
ttt
jjj
Column 1 Column 2 Column 3
The first column contains lines unique to aaa.txt, the second column contains lines unique to bbb.txt, and the third column contains lines common to both aaa.txt and bbb.txt. The columns are delimited by tab characters \t
.