The Linux comm Command Options
The comm command in Linux is a powerful tool used to compare two sorted files and display the lines that are unique to each file, as well as the lines that are common to both files. The comm command offers several options that allow you to customize the output and control the comparison process.
1. Basic Usage
The basic syntax of the comm command is as follows:
comm [options] file1 file2
Here, file1 and file2 are the two files you want to compare.
2. comm Command Options
The comm command supports the following options:
-1: Suppress the output of the lines that are unique tofile1.-2: Suppress the output of the lines that are unique tofile2.-3: Suppress the output of the lines that are common to bothfile1andfile2.
Here's a Mermaid diagram that illustrates the different outputs of the comm command with these options:
3. Examples
Let's consider two files, file1.txt and file2.txt, with the following contents:
# file1.txt
apple
banana
cherry
date
# file2.txt
banana
cherry
orange
-
Default Output:
$ comm file1.txt file2.txt apple banana cherry date orange -
Suppress Unique to
file1:$ comm -2 file1.txt file2.txt banana cherry orange -
Suppress Unique to
file2:$ comm -1 file1.txt file2.txt apple banana cherry date -
Suppress Common Lines:
$ comm -3 file1.txt file2.txt apple date orange
By using these options, you can customize the output of the comm command to suit your specific needs when comparing two sorted files.
