The comm command

The comm command shows the lines unique to file_1 and file_2 along with the common lines in them. We can use various options while using the command in the scripts:

    $ cat file_1
    Barack Obama
    David Cameron
    Narendra Modi
    
    $ cat file_2
    Barack Obama
    Angela Markel
    Vladimir Putin
    
    $ comm --nocheck-order file_1 file_2
          Barack Obama
      David Cameron
        Engela Merkel
      Narendra Modi
        Vladimir Putin
  

In the preceding example, we can see the following:

  • The first column shows the unique lines in file_1
  • The second column shows the unique lines in file_2
  • The last column shows the content common to both files

The output shows that the unique lines in file_1 are David Cameron and Narendra Modi. The unique lines in the second file are Engela ...

Get Learning Linux Shell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.