Linux compare files to output different content
As far as I know, there are several ways to compare rows of two files to output their differences:
1) Comm Mission:
Comm [ -123] file1 file2 [> Sfile]
Note:file1,file2 must be firstly sorted!
-1/2/3 means:-1-----rid of the retained contents in File1
-2-----rid of the retained contents in File2
-3-----rid of the communal lines in both two files
As mentioned above, the premise of the Comm command is to use two sorted files!
The command is a comparison of the two sorted files. where file1 and file2 are sorted files. Comm reads the two files and then generates three columns of output: Rows that only appear in file1, rows that occur in file2, and rows that exist in two files. If the filename is "-", read from the standard input.
Options 1, 2, or 3 suppress the corresponding column display. For example, comm-12 shows only rows that exist in two files; comm-23 displays only those rows that appear in the first file but not in the second file; comm-123 doesn't show anything.
2) grep Mission:
Grep-v-F file1 file2
/* Note:: This method in comparison with the number of comparisons, text contrast does not recommend the use of * *
3) awk Mission:
awk ' {print nr,$0} ' file1 file2 |sort-k2|uniq-u-F 1|sort-k1|awk ' {print $} '
Or:
awk ' {print $} ' file1 file2 |sort|uniq-u
4) diff Mission:
diff [-opt] file1 file2
Note : More wonderful tutorials Please pay attention to the triple computer tutorial section, triple Computer office group: 189034526 welcome you to join