Linux comm

The 'comm' command compares two files or streams. By default, 'comm' will always display three columns. First column indicates non-matching items of first file, second column indicates non-matching items of second file, and third column indicates matching items of both the files. Both the files has to be in sorted order for 'comm' command to be executed.

Syntax:

Example:

Linux Comm Filter1

Look at the above snapshot,

First column displays non-matching items of first file 'file1.txt' (Sehwag, Yuvi)

Second column displays non-matching items of second file 'file2.txt' (Zadeja)

Third column indicates matching items of both the files (Dhoni, Dravid, Sachin)


To Display Single Column

If you want to output a single column, you have to specify number of the columns which are not to be displayed.

Syntax:

comm -23(To display first column)

comm -13(To display second column)

comm -12(To display third column)

Example:

comm -23 file1.txt file2.txt

comm -13 file1.txt file2.txt

comm -12 file1.txt file2.txt

Linux Comm Filter2

Look at the above snapshot, column number which needs to be displayed are not mentioned in the 'comm' command.

Next TopicLinux sed




Latest Courses