Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 2640  / 3 Years ago, wed, june 2, 2021, 6:10:35

I am trying to get the name of the user from one file and their corresponding details from my other file. I use awk:



awk -F : '{ print $1 }' user-name


it gives me the list of all the user's. So now how can I match these names with the other file and get a output like:



user-name id contact-details


The format of the two files is like follows:



1.user-name



Tarun:143
Rahul:148
Neeraj:149


2.user-details



Tarun:[email protected]
Neeraj:[email protected]
Rahul:[email protected]


what I'm trying to get is like:



Neeraj:149:[email protected]
Rahul:148:[email protected]
Tarun:143:[email protected]

More From » scripts

 Answers
3

You can use the join command



join -t ":" username contacts


username file has the format



user1:id1
user2:id2


contacts has the format



user1:contact1
user2:contact2


When the file is not sorted then you can do the following



sort -b username > username.sorted
sort -b contacts > contacts.sorted


and then run the join command on username.sorted and contacts.sorted



or as another post pointed out you can do it directly using



join -t ":" <(sort -b username) <(sort -b contacts)

[#23547] Thursday, June 3, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rstride

Total Points: 305
Total Questions: 112
Total Answers: 118

Location: Mali
Member since Sat, Dec 26, 2020
3 Years ago
;