junda
junda

Reputation: 51

Unix - how to merge two files using awk?

I have two unl files:

#a.unl
310123
23371043
23370043
300054
700988
#twenty records like these

and

#b.unl
310123|name1|
311123|name2|
#almost a hundred records like these
23371043|namex|

i want to use awk so that I could join a.unl records with names from b.unl like this:

#c.unl
310123|namea|
23371043|nameb|
23370043|namec|
300054|named|
700988|namee|

Is it possible using awk? or do I have to use alternative like join?

Thank you very much for your help

Upvotes: 0

Views: 759

Answers (1)

devnull
devnull

Reputation: 123458

Using awk:

awk -F'|' 'NR==FNR{a[$0];next}$1 in a' a.unl b.unl

Upvotes: 1

Related Questions