Use of join in Shell programming _ programming

Source: Internet
Author: User
http://www.51testing.com/?uid-45739-action-viewspace-itemid-185211

JoinSimilar to the Join method in db, there is also a left join right join INNER JOIN, etc.
Specifies the way the join is specified by the parameter-A.
-A1 represents a row that does not match in the first file, that is, a LEFT join
-A2 represents a row that does not match in the second file, that is right join
-O 1.1 2.1-o is an output parameter, 1.1 indicates that the first column of the first file is output; 2.1 indicates that the first column of the second file is output
-T ' | ' is a separator parameter that specifies | as the field separator
-J 1.1 2.1-j is a field parameter that represents a connection, where the first column of the first file and the first column of the second file are associated
Look at the following examples of operations:
The contents of the file Test1 are:
001:002
002:shdha
003:sjdh
004:dhahh
The contents of the file Test2 are:
001:aaaa
002:bbbb
008:hhhhh

Using the command join-t ': ' test1 test2 output is:
001:002:aaaa
002:shdha:bbbb
Using the command join-a1-t ': ' test1 test2 output is:
001:002:aaaa
002:shdha:bbbb
003:sjdh
004:dhahh
Using the command join-a1-a2-t ': ' test1 test2 output is:
001:002:aaaa
002:shdha:bbbb
003:sjdh
004:dhahh
008:hhhhh
Use the command join-o 1.2-t ': ' test1 test2 output is:
002
Shdha
Also see examples of output if multiple identical keys exist
# Cat AA
123|11|aaaaa
124|12|abasf
125|12|aaccc
126|13|ccccc
127|14|ccvvv
128|17|vgfgd
# Cat BB
12|aaa
12|ddd
13|aaa
14|aaa
Command join-2 1-1 2-t ' | '-o 1.1,1.2,1.3 aa BB generation
124|12|ABASF #多次输出12这个KEY
124|12|abasf
125|12|aaccc
125|12|aaccc
126|13|ccccc
127|14|ccvvv

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.