Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know grep -F can search for literal strings, but I want to do something like

while read word; do
  grep -F "^$word$" FILE;
done < wordlist

i.e. the words need to be treated literally, at the same time, ^ and $ conditions need to be satisfied.

How to do this?

share|improve this question
up vote 8 down vote accepted

Use the -x option:

grep -x -F word file

-x will "consider only input lines that use all characters in the line ... to match an entire fixed string".

share|improve this answer
thanks, i ll accept this in 10 mins. so there is no generalized way to treat some part of pattern as regex and some part as literal, is it? – user13107 Jun 28 '14 at 7:36
Not other than escaping the special characters, no. – Michael Homer Jun 28 '14 at 7:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.