This question already has an answer here:

I've got a file with with a list of words each delimited by tabs. I'm trying to use grep to search for two of the words, but I can't figure out how to include the tab in the search string. I've tried:

grep -i -e "word1 \tword2"

along with several variations, but I still can't figure it out. Anyhelp?

marked as duplicate by Eric Renouf, Anthon, Networker, Julie Pelletier, Stephen Harris Aug 28 '16 at 20:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • The answers below are helpful, but are also copying your example of a space followed by a tab. If your delimiter is only a tab, adjust accordingly. – Jeff Schaller Sep 29 '15 at 11:04


grep "word1 $(printf '\t')word2" <file

Note that you need to escaped any characters in word1 and word2 if they're expanded by the shell.

In bash, zsh and ksh variants, you can use:

grep 'word1'$'\t''word2' <file

If you don't mind switching to awk:

awk '/word1 \tword2/' <file

will work in all POSIX systems.


You might like to try this:

grep -e "word1.*word2" inputfile.txt
  • That does not match a tab character between two words. – jordanm Sep 29 '15 at 1:54
  • 3
    I think you have . and * around the wrong way. – DarkHeart Sep 29 '15 at 1:54
  • Answered before I had my coffee. Thanks @DarkHeart – rcjohnson Sep 29 '15 at 18:14

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