Linux comm command: compare two sorted files line by line
Linux comm command Function Description
Use the comm command to compare two files that have been sorted and display their results.
Linux comm command Syntax
comm [Option] [file1] [file2]
The meaning of each option in the command is shown in the table:
Option | Description |
---|---|
-1 | Do not output lines specific to file 1 |
-2 | Do not output lines specific to file 2 |
-3 | Do not output lines that are common to both files |
Linux comm command Demo
Compare the file contents of file1 and file2
[root@rhel ~]# cat file1
a
aa
[root@rhel ~]# cat file2
a
bb
// View the file contents of files file1 and file2
[root@rhel ~]# comm file1 file2
a
aa
bb
Compare file1 and file2, displaying only the contents of the same lines of data in file1 and file2
comm -12 apidemos.com.sort.txt apidemos.com.txt
Output: