This tutorial explains Linux “comm” command, options and its usage with examples.
DESCRIPTION
Compares two files and tells you what line numbers are different.
SYNOPSIS
comm [OPTION]… FILE1 FILE2
OPTIONS :
-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,
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
$ 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
$ comm -3 file1.txt file2.txt def klm
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Apply for Programming Internship
- Buy Information Technology Books
- Practice Programming MCQs
- Apply for Linux Internship
- Buy Linux Books