1

I have two files.

Match the 1st column of first file to 1st column of second file and print entire line of the second file.

Second file is a <tab> separated file.

I have tried many awk one liners, but all remove duplicate values. Like A and C here. I want to preserve these.

File 1:

A
B
C
D
A
C

File 2:

A abc
B cde
C abe
D acc

Output:

A abc
B cde
C abe
D acc    
A abc
C abe
3

Try this:

$ awk 'FNR==NR{a[$1]=$0;next};{print a[$1]}' file2 file1
A abc
B cde
C abe
D acc
A abc
C abe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.