“comm” Command Usage Examples in Linux

«
»

This tutorial explains Linux “comm” command, options and its usage with examples.

comm – Select or reject lines common to two files.

DESCRIPTION

advertisement

Compares two files and tells you what line numbers are different.

SYNOPSIS

comm [OPTION]… FILE1 FILE2

OPTIONS :

advertisement
advertisement

-1
Suppress the output column of lines unique to file1.
-2
Suppress the output column of lines unique to file2.
-3
Suppress the output column of lines duplicated in file1 and file2.
file1
Name of the first file to compare.
file2
Name of the second file to compare.

EXAMPLES

Two provide examples for this command, lets consider two files :

$ cat file1.txt
abc
def
ghi
$ cat file2.txt
abc
ghi
klm

In the below examples,

advertisement

First column displays the lines unique in file1
Second column displays the lines unique in file2
Third column displays the lines that are common in both the files.

1. Simple Command Usage

$ comm file1.txt file2.txt
		abc
def
		ghi
	klm

2. Suppress first column

advertisement
$ comm -1 file1.txt file2.txt
	abc
	ghi
klm

3. Suppress second column

$ comm -2 file1.txt file2.txt
	abc
def
	ghi

3. Suppress third column

advertisement
$ comm -3 file1.txt file2.txt
def
	klm

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.