Find pattern from one file listed in another

What version of grep are you using? I tried your code and got the following results:

$ grep -f file1 file2
ENSG00000187546
ENSG00000113492
ENSG00000166971,ENSG00000186106

If you just want the results that match you can use grep's -o switch to report only the things that match:

$ grep -o -f file1 file2 
ENSG00000187546
ENSG00000113492
ENSG00000166971

grep version

$ grep --version
grep (GNU grep) 2.14
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

Stray characters in F1.txt?

While debugging this further I noticed several stray spaces at the end of the 2nd line in the file F1.txt. You can see them using hexdump.

$ hexdump -C ff1
00000000  45 4e 53 47 30 30 30 30  30 31 38 37 35 34 36 0a  |ENSG00000187546.|
00000010  45 4e 53 47 30 30 30 30  30 31 31 33 34 39 32 20  |ENSG00000113492 |
00000020  20 0a 45 4e 53 47 30 30  30 30 30 31 36 36 39 37  | .ENSG0000016697|
00000030  31 0a                                             |1.|
00000032

They show up with as ASCII codes 20. You can see them in them here: 32 20 20 0a.

Tags:

Grep