Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract only whole word using grep

I've got a big text file. I need to extract all the lines which contains the exact word "DUSP1". Here an example of the lines:

9606    ENSP00000239223 DUSP1   BLAST
9606    ENSP00000239223 DUSP1-001 Ensembl

I want to retrieve the first line but not the second one.

I tried several commands as:

grep -E "^DUSP1"
grep '\<DUSP1\>'
grep '^DUSP1$'
grep -w DUSP1

But none of them seem to work. Which option should I use?

like image 934
Titus Pullo Avatar asked Jul 12 '13 13:07

Titus Pullo


1 Answers

If you want to grep exactly the whole word, you can use word boundaries like this:

grep '\bDUSP1\b'

This matches for the exact word at the beginning and at the end.

like image 53
Phitherek_ Avatar answered Oct 05 '22 12:10

Phitherek_