join to see the literal meaning (join/participate) can be known that he is processing data between two files, and, mostly in the processing " two files with "same data" in the line, just add him together "means. Let's use the simple example below to illustrate:
[Email protected] ~]#Join[-ti12] file1 file2 options and Parameters:-T:JoinBy default, data is separated by a space character, and compared to the first field data, if two files are the same, two data lines are linked, and the first field is placed first! -I: Ignoring the difference in case;-1: This is a number.1, representing the meaning of "the first file to be analyzed with that field";-2: Represents the meaning of "the second file is to be analyzed with that field". Example one: Using root as the identity, the/etc/passwdand/etc/Shadow related data integration into one column [email protected]~]#Head-N3/etc/passwd/etc/Shadow==>/etc/passwd<==root:x:0:0: root:/root:/bin/bashbin:x:1:1: bin:/bin:/sbin/nologindaemon:x:2:2:d aemon:/sbin:/sbin/Nologin==>/etc/shadow <==root:$1$/3aqpe5e$y9a/d0bh6relas:14120:0:99999:7::: Bin:*:14126:0:99999:7: ::d Aemon:*:14126:0:99999:7::: # The data from the output can be found in the leftmost fields of these two files are accounts! and by: separate [[email protected]~]#Join-T':'/etc/passwd/etc/shadowroot:x:0:0: root:/root:/bin/bash:$1$/3aqpe5e$y9a/d0bh6relas:14120:0:99999:7:: : bin:x:1:1: bin:/bin:/sbin/nologin:*:14126:0:99999:7: ::d aemon:x:2:2:d aemon:/sbin:/sbin/nologin:*:14126:0:99999:7::: # Through this action, we can combine two files in the first field of the same person into one line! # The same field for the second file is not displayed (because it's already on the first line!) ) Example two: we know/etc/passwdThe fourth field is the GID, the GID record in/etc/The third field in group, how do I integrate two files? [[Email protected]~]#Head-N3/etc/passwd/etc/Group==>/etc/passwd<==root:x:0:0: root:/root:/bin/bashbin:x:1:1: bin:/bin:/sbin/nologindaemon:x:2:2:d aemon:/sbin:/sbin/Nologin==>/etc/group <==root:x:0: rootbin:x:1: root,bin,daemondaemon:x:2: root,bin,daemon# from the above can be seen, there is indeed the same part Oh! Hurry up and integrate! [[Email protected]~]#Join-T':'-1 4/etc/passwd-2 3/etc/Group0: root:x:0: root:/root:/bin/Bash:root:x:root1: bin:x:1: bin:/bin:/sbin/Nologin:bin:x:root,bin,daemon2:d aemon:x:2:d aemon:/sbin:/sbin/nologin:daemon:x:root,bin,daemon# the same, the same field part is moved to the front! So the contents of the second file are no longer displayed. # Ask the reader to match the actual content of the two files shown above!
This join is really helpful when dealing with two related data files! For example, in the above case, my/etc/passwd,/etc/shadow,/etc/group are related, among them/etc/passwd,/etc/shadow account-related,/etc/passwd,/etc/ Group is based on the so-called GID (account number definition) as his relevance. Based on this correlation, we can put the relational data together! This is very helpful in processing the data!
In addition, special attention is paid to the before using join, the files you need to work with should be sorted in advance (sort) ! Otherwise some pairs of items will be skipped! Special attention!
Reference:http://vbird.dic.ksu.edu.tw/linux_basic/0320bash.php#join