count number of tab characters in linux count number of tab characters in linux unix unix

count number of tab characters in linux


Use tr to discard everything except tabs, and then count:

< input-file tr -dc \\t | wc -c


Bash uses a $'...' notation for specifying special characters:

grep -c $'\t' foo


Use a perl regex (-P option) to grep tab characters.

So, to count the number of tab characters in a file:

grep -o -P '\t' foo | wc -l