
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
How to join lines of two files on a common field in Linux?
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.
Syntax
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 |
---|---|
1 | -a, FILENUM Also print not pairable lines from file FILENUM, where FILENUM is 1 or 2, corresponding to FILE1 or FILE2 |
2 | -e EMPTY Replace missing input fields with EMPTY |
3 | -i, --ignore-case Ignore differences in case when comparing fields |
4 | -j FIELD Equivalent to ‘-1 FIELD -2 FIELD’ |
5 | -o FORMAT Obey FORMAT while constructing output lines |
6 | -t CHAR Use CHAR as input and output field separator |
7 | -v FILENUM Like -a FILENUM, but suppress joined output lines |
8 | -1 FIELD Join on this FIELD of file 1 |
9 | -2 FIELD Join on this FIELD of file 2 |
10 | --header 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 |
12 | --help Displays a help message and then exits. |
13 | --version 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
- Related Articles
- How to merge lines of files in the Linux system?
- How to sort lines of text files in Linux?\n
- How to Join Several Partitions on Linux
- How to swap two files in Linux command line?
- How to search contents of multiple pdf files on Linux?
- How to Recursively Search all Files for Strings on a Linux
- How to find all files with names containing a string on Linux?
- How to Append Contents of Multiple Files Into One File on Linux?
- How to join points on a scatterplot with smooth lines in R using plot function?
- Count Duplicate Lines in a Text File on Linux
- Find and tar Files on Linux
- How to download APK files from Google Play Store on Linux
- How to compare two sorted files line by line in the Linux system?
- State any two properties of magnetic field lines.
- How to retrieve a specific number of lines from files in PowerShell?
