Usage: comm [Option]... file 1 file 2
Compare sorted files 1 and 2 row by row.
If no option is included,ProgramGenerates three output columns. The first column contains the rows specific to file 1, the second column contains the rows specific to file 2, and the third column contains the rows common to the two files.
①-1Does not output lines specific to file 1
②-2Do not output lines specific to file 2
③-3No rows are output for the two files.
-- Check-orderCheck whether the input is correctly sorted, even if all input rows are correct
-- Nocheck-orderDo not check whether the input is correctly sorted
-- Output-delimiter = STR by Str
Explanation:
1. -- check-order
Default command.If you do not want to check the sorting, you can -- nocheck-order.
2. -- output-delimiter = Str
STR is an expression.;It can be any non-special character.
3.Parameters can be mixed
-1,-2
It can be written as-12, which is the same as that used by Common commands.
Instance:
1.establish a.txt
Add Element
Apple
Orange
Gold
Silver
Steel
Iron
2. Establish B .txt
Add Element
Orange
Gold
Cookies
Carrot
You can try to directly compare:Comm a.txt B .txt
You will find an error with no sorting.
3. Sorting
Sort a.txt-O a.txt; sort B .txt-O B .txt
4. Comparison
$ Comm a.txt B .txt
The result is actually three columns. The first column is unique to file 1.-1 indicates that the first column is deleted.
The second column is unique to file 2.-2 indicates deleting the second column.
The third column indicates the common columns.-3 indicates that the common columns are deleted.
4.1 print the intersection:
$ Comm-12 a.txt B .txt
4.2 print different lines in two files
$ Comm-3 a.txt B .txt
Add a small modification. The two columns are not good-looking. Use sed to delete the \ t at the beginning of the row.
$ Comm-3 a.txt B .txt | SED's/^ \ t //'
Original
Http://www.16kan.com/post/195690.html