grep a tab in UNIX grep a tab in UNIX unix unix

grep a tab in UNIX


If using GNU grep, you can use the Perl-style regexp:

grep -P '\t' *


The trick is to use $ sign before single quotes. It also works for cut and other tools.

grep $'\t' sample.txt


I never managed to make the '\t' metacharacter work with grep.However I found two alternate solutions:

  1. Using <Ctrl-V> <TAB> (hitting Ctrl-V then typing tab)
  2. Using awk: foo | awk '/\t/'