join Command Examples in Linux

join command joins lines of two files on a common field.

Syntax:

# join [OPTION]... FILE1 FILE2

For each pair of input lines with identical join fields, write a line to standard output. The default join field is the first, delimited by whitespace. When FILE1 or FILE2 (not both) is -, read standard input.

join Command Examples

1. To join and show the common lines from given input files:

# join file1.txt file2.txt 

2. To print the unpairable lines from specified file:

# join -a 1
# join -a 2 

3. To replace the missing fields with empty:

# join -e EMPTY 

4. To ignore the case difference when comparing:

# join -i file1.txt file2.txt
# join --ignore-case file1.txt file2.txt 

5. To obey format while constructing output:

# join -o FORMAT file1.txt file2.txt 

6. To use the CHAR as input and output field separator:

# join -r CHAR file1.txt file2.txt 

7. To print unpairable and suppress joined:

# join -v 1 file1.txt file2.txt 

8. To check the input is sorted:

# join --check-order file1.txt file2.txt 

9. To not to check the input is sorted:

# join --nocheck-order file1.txt file2.txt 

10. To display the help and exit:

# join --help

11. To get the version info:

# join --version 
Related Post