Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux comm Command

Linux comm Command

Linux Command Reference Linux Command Reference

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 options are specified, the results are shown in 3 columns: column 1 contains lines that appear only in the first file, column 2 contains lines that appear only in the second file, and column 3 contains lines that appear in both files. If a filename is given as -, the comm command reads data from standard input.

Syntax

comm [-123][--help][--version][第1个文件][第2个文件]

Parameters:

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

The output of executing the comm command is as follows:



[root@localhost text]# comm aaa.txt bbb.txt 

aaa

                bbb

                ccc

        aaa

ddd

eee

111

222

        hhh

        ttt

        jjj

第一列  第二列  第三列

The first column of the output contains only lines appearing in aaa.txt, the second column contains lines appearing in bbb.txt, and the third column contains lines appearing in both aaa.txt and bbb.txt. The columns are delimited by the tab character \t.

Linux Command Reference Linux Command Reference