Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/Linux/Compare Files with Comm

September 6, 2020

Compare Files with Comm

Here’s a command that will compare two files and display the only entries in the first file that are missing in the second file. To do this, there’s a compare command in Linux Bash called comm that comes with several options. The option we are interested in is the comm -23 which exactly does that. Let me demonstrate.

Let’s say file a.txt contains:

one
two
three
four
five
six
seven
eight
nine
ten

one two three four five six seven eight nine ten

And file b.txt contains:

one
three
four
five
nine

one three four five nine

We then run comm command using the option -23.

comm -23 a.txt b.txt > c.txt

comm -23 a.txt b.txt > c.txt

The contents of c.txt is:

two
six
seven
eight
ten

two six seven eight ten

Filed Under: Linux Tagged With: -23, comm, compare

Content delivered to your email

About Me

I'm Ulysses, a Cloud Engineer at Cardinal Health based in Columbus, Ohio. I’m a certified AWS Solutions Architect. This website is my way of documenting the things I have learned in the Cloud. When off the grid, I enjoy riding my electric skateboard. I have surfed, snowboarded and played the saxophone in the past. I hope you will find this site helpful. It's powered by WordPress and hosted in AWS LightSail.

  • Cloud
  • Linux
  • Git

Copyright © 2012–2021