Use the comm command line tool in Linux

Source: Internet
Author: User
Linux comm command line tool-general Linux technology-Linux technology and application information, the following is a detailed description. If you want to compare the content of the two text files in Linux Command Line Mode, find the content that is simultaneously included in the two text files, you can use the Linux System Tool comm for processing. The premise is that the two compared text files are ordered. You can use sort for processing. The specific operation method is as follows:

The original file is as follows:
A.txt
D
C
B
A
B .txt
G
F
B
A
Sorting
Sort a.txt> a1.txt
Sort B .txt> b1.txt
The processing result file is as follows:
A1.txt
A
B
C
D

B1.txt
A
B
F
G
Comparison
Comm a1.txt b1.txt
A
B
F
G
C
D
The output result contains three columns, of which 3rd columns show the content contained in both files.
The 1th column is only included in the first a.txt file.
The 2th column is only included in the B .txt file.

You can use parameters to specify the columns to be displayed, for example:
Comm a1.txt b1.txt-12
A
B
-12 indicates that no 1st or 2nd columns are displayed, and only 3rd columns are displayed.

-1: column 1st is not displayed. Column 2 and 3 are displayed.

-Column 3 and Column 2nd are not displayed in column 13.
Related Article

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.