grep multiple rows from file.

Hi, I have file1 that contains many columns as show the first three below:

"At1g29930"     198     2105
"At5g46430"     5569     9576
"At1g64740"     1908     2505
"At5g46430"     6717     11317
"At1g64740"     453     655
"At1g12470"     33     18
"At1g80680"     149     262
"At1g23040"     6351     2620
"At1g31390"     -18     87
"At5g19860"     -30     68
"At1g80470"     -49     85
"IC-At1g29930-1 um"     2203     1713
"IC-At1g29930-5 um"     4873     3668
"At5g19860.1"     90     132
"At5g20520"     6     81
"At1g80680.1"     123     186

What I want is to extract the rows from file1 by the first column that contains my following list in file2:

At5g46430
At1g64740
At1g12470
At1g80680
At1g23040
At1g31390
At5g19860
At1g80470
At1g29930
At5g20520

Members in file2 are unique but in file1 they may have multiple copies or iso-forms, like At1g80680 and At1g80680.1. My challenge is to get the rows in file1 that matches exactly by

grep -wf file2 file1 > file3; 

If there is multiple match, get one (or the first one?) and ignore the rest (eg At1g29930, not IC-At1g29930-1 um or IC-At1g29930-5 um), but it did not work. Any help is highly appreciated!

something like this,

$sed -n 's/\"\(At[^ \.]\)\" ./\1/gp' input | sort -u
At1g12470
At1g23040
At1g29930
At1g31390
At1g64740
At1g80470
At1g80680
At5g19860
At5g20520
At5g46430

 
awk -v t="\"" '/^\"?At/&&NR==FNR{gsub(t,"",$1);a[$1]=1;next}
 {if(a[$1]) print}' file1 file2

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums