comm command is used in Linux to compare two sorted files line by line and returns the unique lines and common lines of the files in separate columns.

Syntax for comm command

comm [option] file1 file2

Here is a list and contents of text files, used for comm command in this tutorial.

Uses of comm command with example

Compare two files

comm file1 file2

Lines unique to first file

comm -1 file1 file2

comm -1 file1 file2

Lines unique to second file

comm -2 file1 file2

comm -2 file1 file2

lines common to both files

comm -3 file1 file2

comm -3 file1 file2

Suppress multiple columns

comm -12 file1 file2

comm -12 file1 file2

cmp command with – -check-order option

 comm --check-order file1 file2

comm --check order file1 file2 comm --check order after sorting both file

cmp command with – -check-order option

comm --nocheck-order file1 file2

comm no-check-order file1 file2

cmp command with –output-delimiter=STR option

comm --output-delimiter=STR file1 file2

cmp command with –total option

comm --total file1 file2

 

Sharing is Caring
Scroll to Top