This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| comm [2025/05/02 04:55] – created ken | comm [2026/01/16 03:37] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ===== comm command in Linux with examples ===== | ===== comm command in Linux with examples ===== | ||
| - | |||
| The ‘comm’ command in Linux is a powerful utility that allows you to compare two sorted files line by line, identifying the lines that are unique to each file and those that are common to both. This command is particularly useful when you have lists, logs, or data sets that need to be compared efficiently. Here, we will explore the syntax, usage, options, and examples of the ‘comm’ command. | The ‘comm’ command in Linux is a powerful utility that allows you to compare two sorted files line by line, identifying the lines that are unique to each file and those that are common to both. This command is particularly useful when you have lists, logs, or data sets that need to be compared efficiently. Here, we will explore the syntax, usage, options, and examples of the ‘comm’ command. | ||
| What is the ‘comm’ Command? | What is the ‘comm’ Command? | ||
| - | + | \\ | |
| - | The ‘comm’ command is used for line-by-line comparison of two sorted files. It reads two files as input and generates a three-column output by default: | + | The ‘comm’ command is used for line-by-line comparison of two sorted files. It reads two files as input and generates a three-column output by default:\\ |
| + | \\ | ||
| Column 1: Lines unique to the first file. | Column 1: Lines unique to the first file. | ||
| Column 2: Lines unique to the second file. | Column 2: Lines unique to the second file. | ||
| Column 3: Lines common to both files. | Column 3: Lines common to both files. | ||
| - | + | \\ | |
| - | Syntax: | + | **Syntax:** |
| - | + | \\ | |
| - | $comm [OPTION]... FILE1 FILE2 | + | < |
| - | + | '$comm [OPTION]... FILE1 FILE2' | |
| - | | + | </ |
| - | | + | '' |
| - | + | ''' | |
| - | Example of the ‘comm’ Command | + | \\ |
| - | + | ==== Example of the ‘comm’ Command | |
| - | Let us suppose there are two sorted files file1.txt and file2.txt and now we will use comm command to compare these two. | + | Let us suppose there are two sorted files file1.txt and file2.txt and now we will use comm command to compare these two.\\ |
| - | Displaying contents of file1 | + | **Displaying contents of file1** |
| + | < | ||
| $cat file1.txt | $cat file1.txt | ||
| Apaar | Apaar | ||
| Line 28: | Line 27: | ||
| Deepak | Deepak | ||
| Hemant | Hemant | ||
| - | + | </ | |
| - | Displaying contents of file2 | + | \\ |
| + | **Displaying contents of file2** | ||
| $cat file2.txt | $cat file2.txt | ||