Note that comm takes sorted files as input. Take a look at the following example:
$ cat A.txt
apple
orange
gold
silver
steel
iron
$ cat B.txt
orange
gold
cookies
carrot
$ sort A.txt -o A.txt ; sort B.txt -o B.txt
$ comm A.txt B.txt
apple
carrot
cookies
gold
iron
orange
silver
steel
The first column of the output contains lines that are in A.txt excluding common lines in
two files. The second column contains lines that are in B.txt excluding common lines. The
third column contains the common lines from A.txt and B.txt. Each of the columns are
delimited by using the tab (\t) character.
Some options are available to format the output as per our requirement. For example:
ff -1 removes first column from output
ff -2 removes the second column
ff -3 removes the third column
$ cat A.txt
apple
orange
gold
silver
steel
iron
$ cat B.txt
orange
gold
cookies
carrot
$ sort A.txt -o A.txt ; sort B.txt -o B.txt
$ comm A.txt B.txt
apple
carrot
cookies
gold
iron
orange
silver
steel
The first column of the output contains lines that are in A.txt excluding common lines in
two files. The second column contains lines that are in B.txt excluding common lines. The
third column contains the common lines from A.txt and B.txt. Each of the columns are
delimited by using the tab (\t) character.
Some options are available to format the output as per our requirement. For example:
ff -1 removes first column from output
ff -2 removes the second column
ff -3 removes the third column