Matching and retreiving numbers

Hi,

I have one file 1.txt with one field consist of following Ids (shortlisted 10 but showing 3 here):

00052
00184
00607

and then second file 2.txt with three fields (very big file):

00052	00184	12.73062
00052	00598	13.51205
00052	00599	13.92554
00052	00600	13.73358
00052	00601	13.64979
00052	00602	13.67168
00052	00603	13.11602
00052	00607	13.25308
00184	00602	 9.99894
00184	00603	 9.79437
00184	00604	 9.86195
00184	00607	 9.58066

I wish to retreive the value where IDs from 1.txt matches as per 2.txt. One more thing, there are no repetitive rows in 2.txt, for example, for 00184 and 00607, only following 1st row is present and not 2nd.
00184 00607 9.58066
00607 00184 9.58066

Required output:

00052	00184	12.73062
00052	00607	13.25308
00184	00607	 9.58066

Thanks.

Try:

awk 'NR==FNR{A[$1]; next} $1 in A && $2 in A' 1.txt 2.txt
1 Like

Thanks. It working. :slight_smile: