You are reading the article How Does Join Work In Linux? updated in September 2023 on the website Speedmintonvn.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How Does Join Work In Linux?
Introduction to Linux JoinIn a certain situation in today’s world, when the data is sparse, it becomes necessary to join 2 files that contain parts of the same data. In other words, using join, one can achieve the utility of “joining” 2 files so that the join output makes more sense and is complete. There are many applications where the join command finds its use. Let us make it more clear to you with an example. Suppose there are 2 files; in one file, we have a list of employees, and in the other, their addresses. Join in Linux comes in handy for these kinds of join situations!
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
Syntax:
The basic syntax attached to the join is:
join [OPTION]… FILE1 FILE2Where FILE1 and FILE 2 are the files, where contents are located, and OPTION denotes the various options we would discuss here, which help achieve the desired requirement.
Syntax:
2. -v option: Way to ONLY print non-paired lines.
3. Join custom columns from 2 files
Syntax:
4. -i / –ignore-case option: Case insensitive join
Syntax:
OR
5. –check-order / –nocheck-order: Check for sort through all input lines.
Syntax:
OR
6. –help option: Display of help message.
Syntax:
Join --help How does Join Work in Linux?Join in Linux finds its application in various uses, and in this section, we will look into some of the most used ones during the explanation of each of them; we will take turns explaining the working of each in due course of the section.
The first and foremost is the basic join, where the intent is to join 2 files through a common key; here, the key is also referred to as an index and acts like matching 2 contents on similar grounds. Think of this as a sports tournament, where teams play against each other on some common ground, may it be goals scored in soccer, runs scored in cricket, and so on. Now since only 2 teams can play against each other in contrast to so many teams in the tournament, there are some common rules to judge the winners and runners-up.
Now, with the same analogous situation, the 2 files will be compared, and wherever the index would match, the contents corresponding to the index will be copied along with a gap. Now, one needs to be careful about any gap or empty character in place as they will tend to be concatenated along. In the next one, there might be conditions where the “index” might be missing from any one of the files, and hence the user may choose to add the non-paired ones during the join with the intent that the result file is something like a union of the files and would contain “best of both worlds”.
Also, one must be aware of the act that the join in Linux is case sensitive. In some scenarios, the user would like to neglect the case of the indexes used for joining. Now, obviously, if the index is a number, the case won’t matter, but in case the index is alphabets, the ascii value of small caps in comparison to all caps is different and hence problematic for Linux to join by default. Hence, the user can use -i to make the indexes case-insensitive during the join.
At last, there are other sets of commands which one can access using –help in Linux, should one feel the need to explore more of Linux join.
Examples of Linux JoinGiven below are the examples mentioned:
Example #1Join with printing all non-paired rows in File 2.
Syntax:
join chúng tôi chúng tôi -a 2Join with printing all non-paired rows in File 1.
Syntax:
join chúng tôi chúng tôi -a 1Output:
Inputs files:
Join with printing all non-paired rows in File 2:
Join with printing all non-paired rows in File 1:
Example #2Join with printing ONLY non-paired rows in File 2:
Syntax:
join chúng tôi chúng tôi -v 2Join with printing ONLY non-paired rows in File 1:
Syntax:
join chúng tôi chúng tôi -v 1Output:
Example #3Syntax:
When the order of custom columns is different:
join chúng tôi chúng tôi -1 2 -2 1When the order of the custom column is the same:
join chúng tôi chúng tôi -j 2Output:
When the order of custom columns is different:
When the order of the custom column is the same:
Example #4Syntax:
join -i chúng tôi file2.txt join --ignore-case chúng tôi file2.txtOutput:
When no option is used, the join returns empty!
Example #5Syntax:
No option
join -i chúng tôi file2.txtUsing the option of check order
join -i --check-order chúng tôi file2.txtUsing the option to not check the order.
join -i --nocheck-order chúng tôi file2.txtOutput:
When the option “–nocheck-order” is not available, an error is reported if there is unsorted data. However, when the “–nocheck-order” option is used, the error is suppressed, and the unsorted line is simply omitted from the process.
Example #6Syntax:
join --helpOutput:
ConclusionWith the set of examples and explanations to the working of join in Linux, you must be quite used to the usage of the same, and this will enable you to experiment more with other arguments of Linux join.
Recommended ArticlesWe hope that this EDUCBA information on “Linux Join” was beneficial to you. You can view EDUCBA’s recommended articles for more information.
You're reading How Does Join Work In Linux?
Update the detailed information about How Does Join Work In Linux? on the Speedmintonvn.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!