From my recent post, we have covered to merge data contents two text files without a common columnar field. We have also covered joining two text files into one text file separated by a delimiter character. Now, from this post, we are going to go thru merging two text files with a common columnar field. Read on.
HowTo: Join Two Text Files with Common Columnar Field via Terminal
Say we have two text files, namely test1.txt and test2.txt, with data content as follows# cat test1.txt
first Fedora
second Redhat
third CentOS# cat test2.txt
first Core 9
second Enterprise Version
third Free OS
Now, the simplest approach to merge data contents of text-based file is by using linux join command like so
# join test1.txt test2.txt
result:
first Fedora Core 9
second Redhat Enterprise Version
third CentOS Free OS
As you noticed, the two text files are basically merged using the common columnar fields namely first, second and third words.
To make it a little bit complex, here we would be joining the first field of the first text file with the second field of the second text file, that would simply be# join -o 1.1 -o 2.2 test1.txt test2.txt
result:
Fedora Core
Redhat Enterprise
CentOS Free
The above join command matched the first field of first text file with the second field of the second text file.
Here's another one matching the second columnar data field of the first text file with the third columnar field of the second text file.# join -o 1.2 -o 2.3 test1.txt test2.txt
result:
Fedora 9
Redhat Version
CentOS OS
Basically, using this approach, text files with and without common field can be joined and merged together with or without consideration to specific field columns,and saved to as another set of data text file. This could also be useful to UNIX text files mostly used by banks and to text files that needs to be merged and joined for a common data use.
Cool. Today is Friday, have a nice weekend!
If you have just subscribed recently and you are new around here, here are my old linux quick tips.
50 Quick Linux Terminal Command Tips Part 1
50 Quick Linux Terminal Command Tips Part 2
50 Quick Linux Terminal Command Tips Part 3
50 Quick Linux Terminal Command Tips Part 4
And if you are more on linux gaming, check out these 113 amazing fedora games. Thanks!
Categories
- HowTos (611)
- Linux Devices (39)
- Linux Diggs (620)
- Linux News (1541)
- Linux Videos (24)
Recent Posts
Blog Archive
-
►
2008
(2302)
-
►
October
(140)
- Linus Torvalds on Linux Distributions
- AMD to Spin off Manufacturing Operations
- MySQL cofounder David Axmark leaving Sun
- Mono to contribute back to CLI; Microsoft says it ...
- Monitor your network with GroundWork Monitor Commu...
- The LXF Guide: Write a Perl module
- 8 Best First-person Shooter Games for Linux
- AppDeploy Community Launches Free Windows Installe...
- Ubuntu Tweak - Sneak Peak at Latest Version!
- POS stack targets Linux netbooks
- RIP LinuxWorld
- Firefox extension blocks dangerous Web attack
- Wikia co-founder to speak at linux.conf.au
- Wikia co-founder to speak at linux.conf.au
- Look Ma, No ‘X’
- Look Ma, No ‘X’
- Forget the damn Linux netbooks. Can Windows replac...
- Forget the damn Linux netbooks. Can Windows replac...
- Amarok 2.0 Beta 2 was released
- 6 Years As A Professional Software Developer
- Amarok 2.0 Beta 2 was released
- 6 Years As A Professional Software Developer
- Distribution Release: EnGarde Secure Linux 3.0.21
- Torvalds talks about his brand new blog
- Become a multimedia pro with the Vector Linux Mult...
- Linux Robot - Watch This Space
- Distribution Release: EnGarde Secure Linux 3.0.21
- Torvalds talks about his brand new blog
- Become a multimedia pro with the Vector Linux Mult...
- Linux Robot - Watch This Space
- Linux-Based E-Voting In Brazil
- Is .NET on Linux Finally Ready?
- Linux-Based E-Voting In Brazil
- Multi-core networking stack ported to PowerPC
- Google rev's photo editor for Linux
- Project releases version 2.0 of open source .Net
- One more 2.6.27 prepatch
- Stallman vs. Clouds
- How to Create and Use a Password Reset Disk in Win...
- OpenOffice.org Grows Up
- 45+ Sources and Sets of Photoshop Custom Shapes
- Clean up your filesystems with fslint
- NPX-9000 UMPC is inexpensive but underpowered
- Will Chrome Find a Home With SaaS?
-
►
October
(140)
Friday, April 18, 2008
HowTo: Join Two Text Files with Common Columnar Field via Terminal
Subscribe to:
Post Comments (Atom)
ILoveTux - howtos and news | About | Contact | TOS | Policy


0 comments:
Post a Comment