Match and extract data using two files

Hello,

Using the information in file 1, I would like to extract from file2 all rows which matchs in column 3.

file 1

1233
1230
1231
1232

file2

  65733.00  19775.00  1220
   65733.00  19793.00  1220
   65733.00  19801.00  1220
   65733.00  19809.00  1231
   65733.00  19817.00  1231
   65733.00  19823.00  1220
   65733.00  19837.00  1220
   65733.00  19841.00  1220
   65733.00  19849.00  1232
   65733.00  19857.00  1232
   65733.00  19873.00  1220
   65733.00  19875.00  1220
   65733.00  19881.00  1220
   65733.00  19889.00  1233
   65733.00  19897.00  1233

Output desired

 65733.00  19761.00  1230
   65733.00  19765.00  1230
   65733.00  19809.00  1231
   65733.00  19817.00  1231
   65733.00  19849.00  1232
   65733.00  19857.00  1232
   65733.00  19889.00  1233
   65733.00  19897.00  1233

I got the output desired using grep -hFf file1 file2 , but is there a best solution using awk.

some times the grep can take values even from columns 1 or 2,, and i need to filter the values only using column 3.

Thanks in advance.

awk 'NR==FNR{a[$1]=$0;next}($3 in a){print}' file1 file2
1 Like

Thanks :slight_smile: