Description, is through file2 content and file1 do compare, finally listed file1 and file2 different parts!
First, prepare two documents:
Catcat file2ce
Second, the comparison method:
Method One:grep command
grep -V-f file2 file1abd
Method Two: Comm command
[Email protected] test1]# Comm- file1 file2abd
Command explanation:
Comm
Function Description: Compare two ordered files.
Syntax: Comm [ -123][–help][–version][1th file] [2nd file]
Additional notes:
This command compares the differences of two sorted files in a column and displays the results.
If no parameters are specified, the results are divided into 3 rows:
Line 1th is only a column that appears in the 1th file,
Line 2nd is a column that appears only in the 2nd file.
Line 3rd is the column that appears in the 1th and 2nd files.
If the given file name is "-", the comm instruction reads the data from the standard input device.
Method Three: awk command
Print out file1, file2 files, first column number, second column two file contents | Then sort by the second row | Delete duplicate rows (Sort-u can also, but it retains a duplicate) | Sort by the first column of rows | print out the second column
awk ' {print nr,$0} ' file1 file2 | Sort -k2| Uniq 1| Sort -k1| awk ' {print $} '
Or:
This is the same as the above, because it does not need to consider the first column above, because it has not been printed.
awk ' {print $} ' file1 file2 | Sort| Uniq -U
Excerpt from: http://kinggoo.com/diffcommgrepawksortuniq.htm?utm_source=tuicool&utm_medium=referral
Compare the contents of a file with the same parts and different parts of Linux