2

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

1 Answer 1

4

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
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .