Forrest logo
back to the comm tool

comm:tldr:905d2

comm: Get lines only found in first file, saving the result to a third file.
$ comm -23 ${file1} ${file2} > ${file1_only}
try on your machine

This command compares the contents of two files, denoted as ${file1} and ${file2}, and outputs the lines that are unique to ${file1} (i.e., lines that exist only in ${file1}) to a new file called ${file1_only}. Here is the breakdown:

  • "comm" is the command used to compare two sorted files line by line.
  • "-23" are options provided to the "comm" command. The option "-2" suppresses printing lines unique to the second file (${file2}), and the option "-3" suppresses printing lines that appear in both files.
  • ${file1} and ${file2} are variables representing the names of the two files being compared.
  • ">" is a redirection operator that redirects the output of the "comm" command to a file.
  • ${file1_only} is a variable representing the name of the output file where the lines unique to ${file1} will be stored.
This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the comm tool