Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-02-2017, 06:12 PM
|
#1
|
Member
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69
Rep: 
|
Add new column from another file
Hi,
I have 2 files.
file1 contains by lines: hash:salt:id
file2 contains by lines: username:hash:salt
I would like to add a new coloumn (id) form file1 to file2.
The new file should contains: username:hash:salt:id
Note: file1 contains less rows than file2
I tried
Code:
paste -d':' file1 file2
, but this solution not good for me.
Thank you
Last edited by freeroute; 08-02-2017 at 06:22 PM.
|
|
|
08-02-2017, 06:26 PM
|
#2
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,437
|
Use join, not paste.
|
|
1 members found this post helpful.
|
08-02-2017, 06:37 PM
|
#3
|
Member
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69
Original Poster
Rep: 
|
Quote:
Originally Posted by syg00
Use join, not paste.
|
Tried, but this command does not work:
Quote:
join <(cat file1.txt | sort ) <(cat file2.txt | sort ) >final_file3.txt
|
I guess because of file1 contains less lines(users).
|
|
|
08-02-2017, 06:54 PM
|
#4
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,437
|
Guess again.
You need to read the manpage - all of it, carefully. Join will join appropriate lines, and ignore unmatched.
|
|
1 members found this post helpful.
|
08-02-2017, 06:56 PM
|
#5
|
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.6
Posts: 5,903
|
from man join
Quote:
join [OPTION]... FILE1 FILE2
|
Please review the man document re: OPTIONs to see which apply to your case.
Edit: I shouldn't take so long to compose, I guess...what syg00 said, too.
Last edited by scasey; 08-02-2017 at 06:57 PM.
|
|
1 members found this post helpful.
|
08-02-2017, 09:47 PM
|
#6
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
You probably also need to feed join with properly sorted data and sort on the field to be joined:
Code:
join ... <(sort -t: -k1,1 file1) <(sort -t: -k2,2 file2)
Last edited by kakistocrat; 08-03-2017 at 02:04 AM.
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 06:42 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|