comm(1)
Compare two sorted files line by line and output unique and common lines.
Synopsis
comm [OPTION]... FILE1 FILE2Description
comm compares two sorted text files and prints three columns: lines unique to FILE1, lines unique to FILE2, and lines common to both. Each column's presence is controlled by suppression flags.
Both input files must be sorted in the same collating order (typically with sort). If a file is -, input is read from standard input.
Common options
| Flag | What it does |
|---|---|
-1 | suppress output of lines unique to FILE1 |
-2 | suppress output of lines unique to FILE2 |
-3 | suppress output of lines common to both files |
-i | ignore case differences when comparing lines |
--check-order | check that input files are properly sorted; exit with error if not |
--nocheck-order | skip checking if files are sorted (default in some versions) |
--output-delimiter=STR | use STR instead of TAB to separate output columns |
Examples
Show all three columns: unique to file1, unique to file2, and common lines
comm file1.txt file2.txtShow only lines common to both files (suppress columns 1 and 2)
comm -12 file1.txt file2.txtShow only lines unique to file1 (suppress columns 2 and 3)
comm -23 file1.txt file2.txtShow only lines unique to file2 (suppress columns 1 and 3)
comm -13 file1.txt file2.txtFind users added or removed by comparing two user lists (requires pre-sorting)
sort users_old.txt > sorted_old.txt && sort users_new.txt > sorted_new.txt && comm -3 sorted_old.txt sorted_new.txtCompare files ignoring case differences
comm -i file1.txt file2.txt