To join lines of two files on a command field, we use the join command in the Linux system. The join command is used to join lines of two files on a common field in the Linux system. If we have two files and we want to join lines of files then no need to combine both files. We can join lines without combining files using the join command. By default, the join field is the first, delimited by blanks.
The general syntax of the join command is as follows −
join [OPTION]... FILE1 FILE2
Note – If FILE1 or FILE2 or both no given then the join command read from standard input.
Brief description of options available in the fmt command.
|Sr.No.||Option & Description|
Also print not pairable lines from file FILENUM, where FILENUM is 1 or 2, corresponding to FILE1 or FILE2
Replace missing input fields with EMPTY
Ignore differences in case when comparing fields
Equivalent to ‘-1 FIELD -2 FIELD’
Obey FORMAT while constructing output lines
Use CHAR as input and output field separator
Like -a FILENUM, but suppress joined output lines
Join on this FIELD of file 1
Join on this FIELD of file 2
Treat the first line in each file as field headers, print them without trying to pair them
|11||-z, --zero -terminated|
Line delimiter is NULL, not newline
Displays a help message and then exits.
It gives info about the version and then exits.
To join lines of two files and prints on standard output, we use the join command without any other option as shown below.
First, we will create two sorted files using the cat command in the Linux system.
$ cat > text1.txt 1 SID 2 SAYANI 3 GAURAV 4 VIKASH $ cat >text2.txt 1 23 2 19 3 22 4 21
Then, we will use the join command to join lines in the Linux system as shown below.
$ join text1.txt text2.txt 1 SID 23 2 SAYANI 19 3 GAURAV 224 VIKASH 21
Note - In order to combine two files, it is necessary to have some common field in both files.
We can create a new file in which the common field is joined as shown below.
$ join text1.txt text2.txt >jointext.txt
To check more information about the join command, we use the --help option with the join command in the Linux operating system as shown below.
$ join --help
To check version information of the join command, we use the --version option with the join command in the Linux operating system as shown below.
$ join --version