Linux comm Command
The Linux comm command is used to compare two sorted files.
This command compares the differences between two sorted files line by line, and displays the results. If no parameters are specified, the results will be displayed 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 the first and second files. If the given file name is-, the comm command will read data from standard input.
Syntax
comm [-123][--help][--version][第1个文件][第2个文件]
Parameters:
- -1 Do not display lines that appear only in the first file.
- -2 Do not display lines that appear only in the second file.
- -3 Do not display lines that appear in both the first and second files.
- --help Online help.
- --version Display version information.
Examples
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 after 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 that appear in aaa.txt, the second column contains lines that appear in bbb.txt, and the third column contains lines that appear in both aaa.txt and bbb.txt. The columns use tabs\tas the delimiter.
Other Extensions
Linux Commands Encyclopedia