10

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?

user3258394
  • 101
  • 1
  • 1
  • 3
  • 1
    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

2 Answers2

9

POSIXly:

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.

cuonglm
  • 153,898
-2

You might like to try this:

grep -e "word1.*word2" inputfile.txt
chaos
  • 48,171
rcjohnson
  • 899