Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

1 Answer 1

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 at 7:36
1  
Not other than escaping the special characters, no. –  Michael Homer Jun 28 at 7:41

Your Answer

 
discard

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.