Shell Join detailed

Source: Internet
Author: User

First paste one, join--help

usage:join [OPTION] ... FILE1 File2for Each pair of the input lines with the identical join fields, write a line tostandard output.   thedefault join field is the first, delimitedby whitespace. When FILE1 or FILE2 (not both) is-, read standard input. -A filenum print unpairable lines coming fromFile FileNum,whereFileNum is 1Or2, corresponding to FILE1 or FILE2-e empty Replace missing input fields with EMPTY-I.,--ignore- CaseIgnore differencesinch  CaseWhen comparing fields-j FIELD equivalent to '-1FIELD-2FIELD'-o format obey format whileConstructing output line-T Char use char asInput and output field separator-V FileNum like-a filenum, but suppress joined output lines-1FIELD Join on ThisFIELD of File1-2FIELD Join on ThisFIELD of File2--help Display ThisHelp and exit--version output version information and exitunless-T CHAR isgiven, leading blanks separate fields and is ignored,ElseFields is separated by CHAR. Any FIELD isa field number counted from 1. FORMAT isOne or more comma or blank separated specifications,each being ' filenum. FIELD'or ' 0'. Default FORMAT outputs the join Field,the remaining fields fromFILE1, the remaining fields fromFILE2, allseparated by CHAR.Important:file1 and FILE2 must is sorted on the join fields. Report Bugs to<[email Protected]>.

And then come to understand.

Join "Command Options" file 1 file 2

Command options can be many, but files can only be two

First of all, the role of join is to get two files in a row and then output the intersection.

Let's look at a basic example:

$ cat A.txt 1  - 2  A 3  One  at
$ cat B.txt 1 0 2 2 3 3 5 3
$ join A.txt B.txt 1  - 0 2  A 2 3  One 3

Why do you get the result above, because join uses a space as a delimiter by default (you can use the-T to set the separator), using the first row as the primary column (the column for intersection).

If you want to get everything out, whether it's paired or not. You can use the-a command.

$ join-A1 A.txt B.txt10223 3 2  at

It can be found that no paired content in the A.txt is output at the end of the file.

It is also possible to lose both A.txt and B.txt.

$ JOIN-A1-A2 A.txt B.txt1022311  3253

But it turns out that typography is different from what we think. The last two lines are not clear whether to fight A.txt or B.txt.

This is the time to use the-o command and the-e command.

$ join-a1-a2-e"_"-O'1.1 1.2 1.3 2.1 2.2 2.3'A.txt B.txt1Abc - 1H02Ccc A 2X23Sed One 3B32Xxx at _ _ __ _ _ 5S3

Where-E indicates what to populate if the element does not exist, and-o indicates which form to output (1.1 represents the first column in file 1).

How to seek A.txt, and B.txt do not?

Then you need to use-V.

Join-v1 A.txt B.txt2

Outputs a part of a that is not in B.

In addition-I ignores case

-j x is equivalent to writing -1x-2x at the same time

That is, specify the x column of two files as the primary column.

How is the join internal implemented, we look at the important requirements in join, each file must be the main column is a well-ordered!!!

is not a bit to know how the join is implemented, that is, two ordered array to find the intersection. is not a deeper understanding of the complexity of joins. If the column size is ignored, O (n + m) can be completed, where n is the number of rows in the file 1, and M is the number of rows in the file 2.

Shell Join detailed

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.