Linux Compare file output different content

Source: Internet
Author: User

Linux compares different output content of files. Currently, I know the following methods to compare the 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 the only retained contents in file1-2 ----- rid the only retained contents in file2-3 ----- rid the communal lines in both two files, as mentioned above, the premise for using the comm command is to address two sorted files! This command compares two sorted files. File1 and file2 are sorted files. Comm reads the two files and generates three output columns: only the rows that appear in file1, only the rows that appear in file2, And the rows that exist in both files. If the file name is "-", it indicates reading from the standard input. Option 1, 2, or 3 suppress the corresponding column display. For example, comm-12 only shows the rows that exist in both files; comm-23 only shows the rows that appear in the first file but not in the second file; comm-123 then nothing is displayed. 2) grep mission: grep-v-f file1 file2/* Note: This method compares the result when comparing numbers. We do not recommend using this method for text comparison */3) awk mission: awk '{print NR, $0}' file1 file2 | sort-k2 | uniq-u-f 1 | sort-k1 | awk '{print $2}' or: awk '{print $0}' file1 file2 | sort | uniq-u 4) diff mission: diff [-opt] file1 file2

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.