EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Linux comm

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » Linux Tutorial » Linux comm

Linux comm

Introduction to Linux comm

The Linux comm command is using to compare the two sorted files line by line and those lines are common and the lines are unique will write to standard output. The comm command providing the comparison facility by column level. The Linux comm command is written by Richard M. Stallman and David MacKenzie.

Syntax of comm command

comm [ OPTION ] … [ FILE 1 ] [ File 2 ]

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

1. comm: Using the comm keyword in the command | syntax. We need to provide at list two files to comm command as an argument.

2. OPTION: As per the requirement, we can provide the valid options in comm command. If we will not use any option in comm command, then the comm command produces the three different column output

  • The first column output holds the lines matches to FILE1
  • The second column output holds the lines matches to FILE2
  • The third or last output column hold those lines are common or similar to both the files

3. If we are providing the two sorted input files as an argument to comm command then only the command will be executed properly without and errors.

How does Linux comm Command work?

The comm command reads the two files as an input but it is providing the single output file. The output file will contain three different output columns. The first column output will display the unique lines of the first input file. Similarly, the second column output will display the unique lines of the second input file and the last or third column will display the common data concerning both the files.

Popular Course in this category
Kali Linux Training (3 Courses, 3+ Projects)3 Online Courses | 3 Hands-on Projects | 21+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,494 ratings)
Course Price

View Course

Related Courses
Linux Training Program (16 Courses, 3+ Projects)Red Hat Linux Training Program (4 Courses, 1+ Projects)

Generally, the columns are separated by “Tab”. If the input file or the input data containing the separator character in it then the output columns will become ambiguous.

Examples of Linux comm

Here are the following examples mentioned:

Comm Command

The comm command is the basic command. Now we will look at the default working of it.

Command:

cat f1.txt
cat f2.txt
comm f1.txt f2.txt

Explanation :

We are having a sample directory. In the same directory, we have two files “f1.txt” file and “f2.txt” file (refer screenshot 1 (a) & (b)). In the “f1.txt” file, we are having some data in it and the same format data is present in the “f2.txt” file. While using comm command on “f1.txt” & “f2.txt”, the first column will display the uncommon data of “f1.txt” file, the second column will display the uncommon data of “f2.txt” file and the third column will display the common data of “f1.txt” file and “f2.txt” file (refer screenshot 1 (c)).

Output :

Linux comm output 1

Screenshot 1 (a)

Linux comm output 2

Screenshot 1 (b)

Linux comm output 3

Screenshot 1 (c)

Example #1 – Comm Command with -1

In the comm command, we are having the functionality to skip the column output data. To skip the first column output data, we can use the “-1” option with comm command.

Command :

comm -1 f1.txt f2.txt

Explanation :

In the above command, we are comparing two files like f1.txt and f2.txt file. Using the comm command, we will get the three output columns. While using the “-1” option, we can skip the 1st column output and display the reaming 2 columns output.

Output :

Linux comm output 4

Example #2 – Comm Command with -2

In comm command, we can skip the second column output data using the “-2” option with the command.

Command :

comm -2 f1.txt f2.txt

Explanation :

In the above command, we are comparing two files like f1.txt and f2.txt file. Using the comm command, we will get the three output columns. While using the “-2” option, we can skip the 2nd column output and display the reaming 2 columns output.

Output :

Linux comm output 5

Example #3 – Comm Command with -3

 In comm command, we can skip the third column output data using the “-3” option with the command.

Command :

comm -3 f1.txt f2.txt

Explanation :

In the above command, we are comparing two files like f1.txt and f2.txt file. Using the comm command, we will get the three output columns. While using the “-3” option, we can skip the 3rdcolumn output and display the reaming 2 columns output.

Output :

output 6

Example #4 – Check Order Option

The check order option is useful to check whether the input file data is correctly sorted order or not.

If the input data is not in sorted order, then the check order option will give an error in comm command.

Command:

comm --check-order f1.txt f2.txt

Explanation :

We are using the check order option in comm command. If the input data is in the sorted format then it will not through an error and if not then it will through an error.

Output :

output 7

Example #5 – Nocheck Order Option

The nocheck order option is not checking whether the input file is in a proper sorted format or not.

Command :

comm --nocheck-order f1.txt f2.txt
od -N5 -c od.txt

Explanation :

We are using the nocheck order option in comm command. The nocheck option is not checking the input data is in sorted format or not. It will use when we need to skip the sorting check.

Output :

output 8

Example #6 – Output Delimiter Option

In comm command, by default, we will get the output in three different columns. However, if we want to change the output as per the separator we can do it via “output delimiter option”. This option is required for specifying the string that we want to use as the separator.

Command :

comm --output-delimiter=Test f1.txt f2.txt

Explanation :

We have seen earlier, in comm command we are getting the output data in three different columns. With the help of the “output-delimiter” option, we can replace the spaces with own input string. In the above command, we have replaced the space with the string “Test”.

Output :

output 9

Conclusion

We have seen the uncut concept of “Linux comm Command” with the proper example, explanation, and command with different outputs. The comm command is useful to compare the two input files whether the input file is in sorted format or not (depend on the condition). In the comm concept, we are satisfying the multiple comparing conditions in it.

Recommended Articles

This is a guide to Linux comm. Here we discuss the how does Linux comm command work with respective programming examples to implement the Command. You may also have a look at the following articles to learn more –

  1. Help Command in Linux
  2. Linux Directory Structure
  3. PS command in Linux
  4. What is Shell in Linux?

All in One Software Development Bundle (600+ Courses, 50+ projects)

600+ Online Courses

50+ projects

3000+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Linux Tutorial
  • Linux Commands
    • CAT Command in Linux
    • PS command in Linux
    • Mkdir Command in Linux
    • rmdir command in Linux
    • mv command in Linux
    • Linux rm Command
    • CHMOD Command in Linux
    • Zip Command in Linux
    • Linux Route Command
    • SCP Command in Linux
    • du Command in Linux
    • Less Command in Linux
    • Copy Command in Linux
    • Head Command in Linux
    • Help Command in Linux
    • Linux History Command
    • hostname Command in Linux
    • GREP Command in Linux
    • Linux Curl Command
    • Linux List Users
    • Linux List Directories
    • Linux Directory Permissions
    • Find Directory Linux
    • Linux User Permission
    • Linux Add User
    • Linux Delete User
    • Linux uniq
    • Linux Filter Commands
    • Linux sort Command
    • Linux Sort by Size
    • Remove dir Linux
    • Linux tr Command
    • Linux Touch Command
    • Linux More Command
    • Linux Cal Command
    • Linux OD
    • Linux Zcat
    • Linux tracepath
    • Linux Sleep
    • Linux bg Command
    • Linux WC
    • Linux Read
    • Linux Write
    • Linux Rename Command
    • Linux Free Command
    • Linux tac
    • Linux Shred
    • Linux wget
    • Linux Date
    • Linux Untar
    • Linux JQ
    • Linux Xargs
    • Linux Mount Command
    • Linux mdadm
    • Linux comm
    • Linux tee Command
    • Tail Command in Linux
    • Linux gzip
    • Linux Directory Structure
    • Linux Alias Command
    • Linux Inode
    • Linux Ping
    • Linux Watch Command
    • Linux Split Command
    • Linux Size
    • Linux Network Stack
    • Linux Diff Command
    • Vim Command in Linux
    • Linux nslookup
  • Basic
    • Introduction to Linux
    • What is Linux
    • Careers in Linux
    • How to Install Linux
    • How to Install Ubuntu
    • How to Install Ubuntu Server
    • How To Install Debian
    • Advantage Of Linux
    • What is Raid in Linux
    • What is Raid 5?
    • Raid 5 vs Raid 6
    • Careers in Linux Administration
    • What is Shell in Linux?
    • Bash Shell in Linux
    • Linux Emulator
    • Linux Operators
    • Linux Apps
    • Linux Keyboard Shortcuts
    • Linux Crontab
    • What is Raid Storage
    • What is Vmware
    • What is RedHat
    • What is Debian
    • Uses of Ubuntu
    • Career In RedHat
    • Linux Distributions
    • Linux From Scratch
    • Linux Format
    • Cheat Sheet Linux
  • Advanced
    • Install VMware
    • Install GRUB
    • Chown Command in Linux
    • Linux Network Command
    • Configuring Linux Network Environment
    • DNS Configuration in Linux
    • Linux Users
    • Create User in Linux
    • DHCP Server in Linux
    • FTP Server in Linux
    • Linux Regular Expression
    • IP Command in Linux
    • Set IP Address in Linux
    • Tar Command in Linux
    • Dynamic Host Configuration Protocol
    • Linux Kill Signals
    • Linux File Permissions
    • Linux File System
    • Linux Create File
    • Linux Concatenate Files
    • Linux Join
    • Linux Process Management
    • Linux Proxy Server
    • Linux System Commands
    • Linux System Logging
    • NFS in Linux
    • Linux LVM
    • Linux Repository
    • Samba Server in Linux
    • Top Commands in Linux
    • Types of Shells in Linux
    • Shell Script Types For Linux
    • GCC Command in Linux
    • Monolithic Kernel
    • YARN Package Manager
    • Linux Sed Replace
    • Linux List Groups
    • Linux Container
    • Linux Find File by Name
    • Create Folder in Linux
    • Linux Move Folder
    • Linux Error Codes
    • Linux Automount
    • Linux HugePages
  • Kali Linux
    • Install Kali Linux
    • Kali Linux Uses
    • Kali Linux Commands
    • Kali Linux Repository
    • Kali Linux Packages
    • Kali Linux root password
    • Kali Linux Alternative
  • Interview Questions
    • Linux Interview Questions
    • Linux System Administration Interview
    • Red Hat Interview Questions

Related Courses

Kali Linux Training

Linux Training Course

Red Hat Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Kali Linux Training Learn More