📄 join.1
字号:
.TH join 1.SH Namejoin \- join files.SH Syntax.B "join [ \-a \fIn\fP] [ \-e \fIstring\fP] [ \-j \fI n m\fP] [ \-o \fIlist\fP] [ \-t \fIc\fP] \fI file1 file2\fP".SH Description.NXR "join command".NXR "file" "comparing".NXR "file" "combining".NXR "join command" "sort command".NXR "join command" "comm command".NXR "relational data base operator"The.PN joincommand compares a field in .I file1 to a field in .IR file2 .If the two fields match, the.PN joincommand combines the line in .I file1that contains the field withthe line in .I file2 that contains the field. The command writesits output to standard output. If you specify a hyphen (-) in the.I file1argument,.PN joincompares standard input to the contents of .IR file2 ..PPThe .PN joincommand compares and combines the input files one line at a time. Eachline in the input file contains one field that .PN joinuses to determine if two lines should be joined. This field is calledthe join field. By default, the.PN joincommand uses the first field in each line as the join field. The command compares the join field in the first line of .I file1to the join field in the first line of .IR file2 . If the twofields match, the command joins the lines. The command then comparesthe join fields in the second line of both files, and so on..PPIn the input files, fields are separated by tab or spacecharacters. The.PN join command reads data from the first field until it encounters a tab or space character, which terminates thefirst field. By default, thecommand ignores tab and space characters, so the next character that is nota tab or space begins thesecond field. The second field is terminated by the tab or space thatfollows it, and the third field begins with the next character that isnot a tab or space. The .PN joincommand reads fields in this way until it encountersa new line character.Any number of tabs or spaces can separate two fields, and any numberof newline characters can separate two lines..PPBoth .I file1and .I file2must be ordered in the collating sequence of the.PN sort \-bcommand on the fields that the two files are to be joined. By default, .PN join uses the first field in each line and collates the same as .PN sort.PN \-b ..PPTo create output, the .PN join command writes the join field, followed by the remaining fields in theline from .I file1, followed by the remaining fields in the linefrom .I file2to the output file. The following demonstrates how linesin the output appear by default:.EXjoin_field file1.field2 file1.field3 file1.field4 file2.field2 file2.field3.EE.PPBy default, the .PN joincommand ignores lines that do not contain identical join fields. Thecommand writes no output for these lines..PPYou can change how .PN joincreates output using command options. For example, you cancause the command to write output for lines that do notcontain identical join fields. You can also specify a .I listusing the.PN \-ooption. In.I list,you supply a list of specifiers in the form.I file.field, where .I fileis either 1 or 2 and .I fieldis the number of the field. For example, 1.2 specifies the second fieldin the first file and 2.4 specifies the fourth field in the secondfile. The following demonstrates how lines in the output appear if youuse these two specifiers:.EXfile1.field2 field2.field4.EE.SS International Environment.IP LC_COLLATE 15If this environment variable is set andvalid,.PN joinuses the international language database named in the definition todetermine collation rules..IP LC_CTYPEIf this environment variable is set and valid,.PN joinuses the international language database named in the definition todetermine character classification rules..IP LANGIf this environment variable is set and valid .PN joinuses the international language database named in the definition todetermine collation and character classification rules. If LC_COLLATEor LC_CTYPE is defined their definition supercedes the definition ofLANG..SH Options.IP \fB\-a[\fIn\fR] 12Write lines that contain unmatched join fields to the output file. You can cause thecommand to write unmatched lines from only one file using .IR n .If you specify 1 in .IR n ,.PN joinwrites unmatched lines only from file 1. If you specify 2,.PN joinwrites unmatched lines only from file 2..IPIf you omit the.PN \-a option, .PN joinwrites no output for unmatched lines..IP "\fB\-\|e\fI s\fR" 12 Writes the string you specify in .I sto the output if youspecify a nonexistent field in the .I listfor the.PN \-ooption. For example, if lines in file 2 contain only three fields,and you specify 2.4 in .IR list ,.PN joinwrites .I sin place of the nonexistent field..IP "\fB\-\|j\fIn m\fR" 12Defines field \fIm\fP in file \fIn\fP to be the join field. The.PN joincommand compares the field you specify in the.PN \-joption to the default join field in the other file.If you omit.IR n ,the .PN joincommand uses the .IR m thfield in both files..IP "\fB\-\|1\fI m\fR"Use the .I mthfield in the first file as the join field. This option is equivalentto using.PN \-j 1 .IR m ..IP "\fB\-\|2\fI m\fR"Use the .I m field in the second file as the join field. This option is equivalentto using.PN \-j 2 .IR m ..IP "\fB\-\|o\fI list\fR" 12Output the joined data according to .IR list .The specifiers in.I listhave the format .IR file.field ,where .I fileis either 1 or 2 and .I fieldis the number of the field..IP \fB\-t\fIc\fR 12Recognize the tab character .IR c .The presence of .I cin a line is significant, both for comparing join fields and creating output..SH Restrictions.NXR "join command" "restricted" If you specify the.PN \-toption, the .PN join command collates the same as.PN sortwith no options..SH ExamplesSuppose that by issuing the following .PN catcommands, you display the files shown in the example:.EX% cat file_1apr 15aug 20dec 18feb 05% cat file_2apr 06aug 14datefeb 15.EEBoth files are sorted in ascending order..PPIf you issue the .PN joincommand without options, the output appears as follows:.EX% join file_1 file_2apr 15 06aug 20 14feb 05 15.EEThe third line in each input file is not joined in the output becausethe join fields (date and dec) do not match..PPTo join the lines in these files and format the output so that thesecond field from each file appears first and the first (join) fieldappears second, issuethe following command:.EX% join \-o 1.2 1.1 2.2 2.1 file_1 file_215 apr 06 apr20 aug 14 aug05 feb 15 feb.EETo write linesthat are unmatched to the output, issue the following command:.EX% join \-a file_1 file_2apr 15 06aug 20 14datedec 18feb 05 15.EE.SH See Alsoawk(1), comm(1), sort(1), sort5(1), environ(5int)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -