Thursday, August 14, 2008

compare two sorted files in unix

If you wanted to compare 2 sorted files then use comm command. comm command compares two sorted files line by line. This command reads the File1 and File2 as parameter and writes a three column output to standard output.

First Column: Lines that are only in File1
Second Column: Lines that are only in File2
Third Column: Lines that are in both File1 and File2

Syntax:

comm [-1] [-2] [-3 ] file1 file2

-1 Suppresses the display of the first column (lines in File1)
-2 Suppresses the display of the second column (lines in File2)
-3 Suppresses the display of the third column (lines both in File1 and File2)

No comments: