tags:

views:

138

answers:

3

I would like to check a number of files for the existence of tab characters (ASCII 0x09) in them. (To assert that my sources are tab-free before committing them to repository.)

Preferably with standard tools. Of course, grep springs to mind, but apparently grep "\t" file.txt doesn't match...?!?

I am aware the answer is probably painfully simple, but I am at a loss.

+5  A: 

Of course, grep springs to mind, but apparently grep "\t" file.txt doesn't match...?!?

That searches for the literal character t. To search for a tab literal with grep, your shell will usually have a literal-insertion method. For example, in bash, use grep $'\t' foo.txt.

John Feminella
Yes, that works. I was unaware that \t, \n etc. didn't work as-is in shell commands.
DevSolar
+1  A: 

try with $'\t' instead of \t

Konstantinos
A: 

I don't believe grep understands the escape sequence \t. Try inserting a literal tab:

grep "<tab>" file.txt

Or, you can use awk instead.

lc
The two answers above were correct. The "literal" tab you mention is interpreted by the bash, not inserted on the command line.
DevSolar
Like I said, you have to insert the literal tab. Most shells have a way to insert a literal tab. The sequence Ctrl-V, Tab in bash for example.
lc
...since the original post never mentioned what type of shell, I left this to you to insert the tab character in an appropriate way, which also differs if you are writing a script vs using the command line.
lc