How to grep tab (\t) in the file on Unix platform
A:
grep '\t' file
works for me, where \t stands for pressing the Tab key, the single quotes prevents it from being discarded as whitespace by the shell.
rsp
2009-12-01 11:27:55
which shell? I am using ksh
Sachin Chourasiya
2009-12-01 11:33:08
yes even I am also surprised, but frankly speaking its not providing any output for me
Sachin Chourasiya
2009-12-01 11:40:01
This doesn't work. It searches for `t`!
Jason Orendorff
2009-12-01 11:40:37
my bad, added explanation :-)
rsp
2009-12-01 11:47:14
+4
A:
If using GNU grep, you can use the Perl-style regexp:
$ grep -P '\t' *
unwind
2009-12-01 11:28:02
It doesn't seem to work against my pattern. Attempting to use that syntax prints nothing. (Is the Mac OS X variant different?)
futureelite7
2010-02-28 15:42:07
@futureelite: According to Apple's docs (http://developer.apple.com/Mac/library/documentation/Darwin/Reference/ManPages/man1/grep.1.html), the Mac OS X grep program should support the -P option. Consider creating a new question, on superuser.com.
unwind
2010-02-28 16:17:46
+2
A:
One way is (this is with bash)
grep -P '\t'
-P turns on perl regular expressions so \t will work.
Edit: beaten to it :), but as unwind says, it may be specific to GNU grep. The alternative is to literally insert a tab in there if the shell, editor or terminal will allow it.
tjmoore
2009-12-01 11:29:04
A:
use gawk, set the field delimiter to tab (\t) and check for number of fields. If more than 1, then there is/are tabs
awk -F"\t" 'NF>1' file