Reputation: 2711
I have a file A with contents
id_7 name_7
id_10 name_10
....
and another file B with all ids:
id_1 ssn_1
id_2 ssn_2
.....
I want to grep the first field (id_7, id_10...) in the second file, however I want the matches to be output like this:
id_1 ssn_1 name_1
....
How do I do this quickly (million of lines in each file) ?
Upvotes: 0
Views: 50
Reputation: 2308
When join
deal with each line of each file, it depends on the common field, so it should be sorted to have the common field to be the same.
join -j 1 <(sort -k 1 file1) <(sort -k 1 file2)
Upvotes: 2