I am using cat to output 6 lines of text from a text file called wordlist.txt. I am piping it to egrep and want to find matches in a second file called 8compdic.txt

command I am using is given below:

cat wordlist.txt | egrep - 8compdic.txt | less

Am getting output which has all the lines in *compdic.txt


Use -f wordlist.txt with grep to tell it to read the patterns from your file. Use -F to tell it that the patterns are fixed strings rather than regular expressions. And use grep -E rather than egrep (for portability):

$ grep -E -F -f wordlist.txt 8compdic.txt | less

If you want to restrict the matches to full lines, add -x to the grep command. Without -x, the word make in wordlist.txt would match words like makes, makeshiftiness and wafermaker in the file you're grepping.

  • The solutions are not working for me. I would like to actually pipe the output to grep and the output lines need to be matched from 8compdic.txt. Thanks. – Mohan Chunkath Feb 15 '17 at 2:06
  • Also would empty lines create a problem? – Mohan Chunkath Feb 15 '17 at 4:51
  • @MohanChunkath Then use -f /dev/stdin with grep. If you use -x, then empty lines will match empty lines. Without -x, empty lines will match all lines. – Kusalananda Feb 15 '17 at 7:15

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