Tuesday, January 7, 2014

Using comm to find unique or common lines between 2 files

Use comm to compare files and show only lines that are unique, requires files to be sorted.

With no options, produce three-column output.  Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files.

Any of the columns can be supressed by adding -1, -2 or -3.

Example: Compare fileA.txt and fileB.txt and show only lines that are unique to fileA.txt
comm -2 -3 <(sort fileA.txt) <(sort fileB.txt)

No comments:

Post a Comment