gentoo.LinuxHowtos.orgedit this article

Comparing Files

Often people compare the differences between two files using diff. But if you needed to do a comparison of similarities between files, comm is the command to use.

Code Listing 1: comm usage syntax

comm [option]  file1  file2

Note: both file1 and file2 need to be sorted before using comm as it does a line by line comparison.

comm outputs three columns: lines that are unique to file1, lines that are unique to file2, and lines that are common to both files. The options '-1', '-2', '-3' will suppress the corresponding columns.

Running comm -2 file1 file2 with the following files, would output five.

Code Listing 2: comm output

File1: 
one 
two 
three 
 
File2: 
one 
five 
three

From http://www.gentoo.org/news/en/gwn/20040823-newsletter.xml


rate this article:
current rating: no votes yet
Your rating:
Very good (1) Good (2) ok (3) average (4) bad (5) terrible (6)

back