Linux compare files to output different content

Source: Internet
Author: User
Tags comparison diff

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.